Article ID: 206884
Article Last Modified on 12/1/2007
BOOL OnPaint( HDC hdc, LPLOGFONT plf )
{
int x=0, y=0; // Output coordinates
DWORD AverageWidth; // Font Width
HFONT hFont, hOldFont; // Font handles
char Buffer[200]; // Output strings
LOGFONT lf; // Logical Font desc.
TEXTMETRIC tm; // Actual Font metrics
/* Make a copy of the Logical Description so we can
make modifications */
lf = *plf;
/*
* Create a Normal font for comparison
*/
hFont = CreateFontIndirect( &lf );
hOldFont = SelectObject( hdc, hFont );
GetTextMetrics( hdc, &tm );
/* Save off the "width" of the font to use later */
AverageWidth = tm.tmAveCharWidth;
/* properly output the text */
y += tm.tmExternalLeading;
wsprintf( Buffer,
"This is Normal text for %s.",
lf.lfFaceName );
TextOut( hdc, x, y, Buffer, lstrlen( Buffer ) );
/* advance for next line and cleanup */
y += tm.tmHeight;
SelectObject( hdc, hOldFont );
DeleteObject( hFont );
/*
* Create a condensed font for output
*/
/* Define our condensed font as half the original */
lf.lfWidth = AverageWidth/2;
hFont = CreateFontIndirect( &lf );
hOldFont = SelectObject( hdc, hFont );
GetTextMetrics( hdc, &tm );
/* properly output the text */
y += tm.tmExternalLeading;
wsprintf( Buffer,
"This is Condensed text for %s.",
lf.lfFaceName );
TextOut( hdc, x, y, Buffer, lstrlen( Buffer ) );
/* advance for next line and cleanup */
y += tm.tmHeight;
SelectObject( hdc, hOldFont );
DeleteObject( hFont );
/*
* Create an expanded font for output
*/
/* Define our expanded font as twice the original */
lf.lfWidth = AverageWidth*2;
hFont = CreateFontIndirect( &lf );
hOldFont = SelectObject( hdc, hFont );
GetTextMetrics( hdc, &tm );
/* properly output the text */
y += tm.tmExternalLeading;
wsprintf( Buffer,
"This is Expanded text for %s.",
lf.lfFaceName );
TextOut( hdc, x, y, Buffer, lstrlen( Buffer ) );
/* cleanup */
SelectObject( hdc, hOldFont );
DeleteObject( hFont );
return TRUE;
}
Keywords: kbdswgdi2003swept kbfont kbgdi kbhowto KB206884