Declare Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lplf As LOGFONT) As Long
CreateFontIndirect creates a font object, which allows a font with given attributes to be used to draw text on a device. The font created by the function is the one which most closely matches the attributes of the logical font information passed via the structure. After your program is finished using the font, it must be deleted by using DeleteObject.
If an error occured, the function returns 0 (Windows NT, 2000: use GetLastError to get the error code). If successful, the function returns a handle to the font just created.
None.
' This code is licensed according to the terms and conditions listed here.
' Use the font used by Windows to draw the title text of
' icons to write the alphabet on window Form1.
Dim lf As LOGFONT ' receives information about the font Windows uses
Dim hFont As Long ' handle to the font that is created
Dim hOldFont As Long ' handle to the font which Form1 previously had selected
Dim retval As Long ' return value
' Get the attributes of the logical font used by Windows to
' draw the title text of icons.
retval = SystemParametersInfo(SPI_GETICONTITLELOGFONT, Len(lf), lf, 0)
' Create a font matching the logical font description.
hFont = CreateFontIndirect(lf)
' Select that font for use in Form1, noting the previous font.
hOldFont = SelectObject(Form1.hDC, hFont)
' Write the alphabet near the upper-left corner of Form1.
retval = TextOut(Form1.hDC, 10, 10, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26)
' Restore the previously selected font for use in Form1.
retval = SelectObject(Form1.hDC, hOldFont)
' Delete the created font to free resources.
retval = DeleteObject(hFont)
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: October 11, 1999
This page is copyright © 1999 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/c/createfontindirect.html