
Set font size in CFontDialog
Quote:
>I used LOGFONT to initialize CFontDialog control settings. I tried to
>assign a certain number to the font size control, but was unable to assign a
>fixed number, such as 11, that I desired. In LOGFONT, the lfHeight member
>uses logical unit, while the CFontDialog returns size in point. I could not
>always set the desired point value from a corresponding lfHeight. Some size
>values would simply be off by 1 point.
Richard,
Here's an example of how I use it:
#define PointSizeToPixel(Point, DPI) (-MulDiv( Point, DPI, 72 ) )
LOGFONT lf;
// lf get's initialised with the last settings
CFontDialog dlg;
dlg.m_cf.lpLogFont = &lf;
dlg.m_cf.nSizeMin = 4;
dlg.m_cf.nSizeMax = 16;
dlg.m_cf.Flags |= CF_PRINTERFONTS | CF_FORCEFONTEXIST |
CF_LIMITSIZE | CF_INITTOLOGFONTSTRUCT;
{
/* Convert the point size to pixels */
/***** The LOGFONT height used here uses the screen
DPI rather than the printers ****/
HDC hDispDC = ::GetDC( m_hWnd );
lf.lfHeight = PointSizeToPixel( lf.lfHeight,
GetDeviceCaps( hDispDC, LOGPIXELSY ) ) / 10;
::ReleaseDC( m_hWnd, hDispDC );
}
if ( dlg.DoModal() == IDOK )
{
/* Save the lfHeight in tenths of a point rather than
in pixels specific to a device */
lf.lfHeight = dlg.m_cf.iPointSize;
}
Dave
--
MVP VC++ FAQ: http://www.*-*-*.com/
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.