Example: Logical FontsCreating a logical font first involves defining the fields in a LOGFONT structure. In the Fontdemo example, we do this at the end of the WM_CREATE handler, filling the LOGFONT structure with values to create a 24x12 script font from one of the stock fonts. The WM_CREATE handler then passes this structure to the Windows API function CreateFontIndirect(), which returns a handle of type HFONT to the new logical font. We can then pass this font handle to fg_logfont() to activate the font for fg_print() in the WM_PAINT handler. Besides showing how to create a logical font, the Fontdemo example shows how to use stock fonts and logical fonts in Fastgraph programs. Its WM_PAINT handler successively activates each of the six stock fonts and calls fg_print() to display the font name using each font (strings are output directly to the client area). It then activates the logical font and again calls fg_print() to display the text "script font" using the logical font. The result looks like this:
Note that we use fg_fontload() to activate a stock font, but we use fg_logfont() to activate a logical font. As shown in the Fontdemo program's WM_DESTROY message handler, you should use the Windows API function DeleteObject() to delete any logical fonts you create. It is not necessary to delete stock fonts.
|
 
copyright 2001 Ted Gruber Software, Inc.