Re: Changing default of static control
"JY" <sd@nospamgroup.com> ha scritto nel messaggio
news:1F7385C4-1922-46F8-8B69-ED53A8DB70FB@microsoft.com...
I want to change the size of the font in my static control. I get the
current
font, and reset its height as shown below, but it does not have the
desired
affect. The font size does increase but not consistently. For example, if
I
increase the font hieght by 10, it actually shows a smaller size than the
original.
As described on LOGFONT MSDN page:
http://msdn.microsoft.com/en-us/library/dd145037(VS.85).aspx
you may want to use the following formula to compute the lfHeight field of
LOGFONT from the desidered font point size:
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
CFont fontStatic;
CFont *pFont = m_StaticText.GetFont();
CFont *pFontNew = new CFont();
if (pFont)
{
LOGFONT logFont;
pFont->GetLogFont(&logFont);
logFont.lfHeight += 30;
I would suggest using the aforementioned formula for logFont.lfHeight.
pFontNew->CreateFontIndirectW(&logFont);
I think that CreateFontIndirect would do just fine.
Why specifying the 'W' suffix? (Just build you code in Unicode mode, which
is the default in VS2005/2008...)
m_StaticText.SetFont(pFontNew);
}
m_StaticText.SetWindowTextW(L"Static Window Text");
Again, I would get rid of the 'W' suffix and just use SetWindowText.
HTH,
Giovanni