![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
Creating FontsThe Windows API function CreateFont creates a new font that a program can use in a form or picture box. CreateFont is declared with the following code:
Declare Function CreateFont Lib gdi32 Alias CreateFontA ( _
ByVal Height As Long, ByVal Width As Long, _
ByVal Escapement As Long, ByVal Orientation As Long, _
ByVal Weight As Long, ByVal Italic As Long, _
ByVal Underline As Long, ByVal StrikeOut As Long, _
ByVal CharSet As Long, ByVal OutputPrecision As Long, _
ByVal ClipPrecision As Long, ByVal Quality As Long, _
ByVal PitchAndFamily As Long, ByVal Face As String) _
As Long
The CreateFont function returns a handle to a logical font that describes the font requested by the CreateFont function. The font mapper then uses this description to select a physical font that matches the description as closely as possible on the computer. The match may not be very close if the fonts available on the computer cannot provide the requested features. Many of the parameters passed to CreateFont determine how the font mapper acts if it cannot exactly match the description. Generally, a program will specify the Face parameter to indicate the font name that should be used and the Height parameter to indicate the fonts size. Many of the other parameters take on default values if they are set to the value zero. CreateFonts parameters are described briefly in the following list. For more information, search for CreateFont in the online help file WIN31WH.HLP.
Windows 3.1 comes with the Arial, Courier New, and Times New Roman fonts. Each of these comes in bold, italic, and bold italic varieties. Even though there is no guarantee that these fonts will be available on all computers, they are more likely to be available than many other fonts. If a program uses them, it increases the chances that it will run correctly on a wide variety of computers.
Using CreateFontAfter the program obtains a logical font handle using CreateFont, it can use the SelectObject API function to make a form or picture box use the font. SelectObject returns the handle of the previously selected font. When the program is done using the new font, it should reselect the original font with SelectObject and then delete the new font with the DeleteObject function. This frees system resources that are held by the font. The VerticalText subroutine in AppointmentBooks module CalVC.CLS creates a font rotated by 90 degrees. It takes as parameters the text to be displayed, the X coordinate that should mark the left edge of the text, and two Y coordinate values between which the text should be centered. It also takes parameters indicating the fonts height and weight, plus values the subroutine should pass to CreateFont indicating whether the font should have italic, underlined, or
|
||||||||||||||||||||||||||||||||||
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.
|