From: JY on
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.

CFont fontStatic;
CFont *pFont = m_StaticText.GetFont();
CFont *pFontNew = new CFont();
if (pFont)
{
LOGFONT logFont;
pFont->GetLogFont(&logFont);
logFont.lfHeight += 30;

pFontNew->CreateFontIndirectW(&logFont);
m_StaticText.SetFont(pFontNew);
}
m_StaticText.SetWindowTextW(L"Static Window Text");

What am I doing wrong?

TIA,
JY
From: Giovanni Dicanio on
"JY" <sd(a)nospamgroup.com> ha scritto nel messaggio
news:1F7385C4-1922-46F8-8B69-ED53A8DB70FB(a)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


From: AliR on
I like CreatePointFont myself.

AliR.

"JY" <sd(a)nospamgroup.com> wrote in message
news:1F7385C4-1922-46F8-8B69-ED53A8DB70FB(a)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.
>
> CFont fontStatic;
> CFont *pFont = m_StaticText.GetFont();
> CFont *pFontNew = new CFont();
> if (pFont)
> {
> LOGFONT logFont;
> pFont->GetLogFont(&logFont);
> logFont.lfHeight += 30;
>
> pFontNew->CreateFontIndirectW(&logFont);
> m_StaticText.SetFont(pFontNew);
> }
> m_StaticText.SetWindowTextW(L"Static Window Text");
>
> What am I doing wrong?
>
> TIA,
> JY


From: Tom Serface on
You might want to take a look at a replacement class like:

http://www.codeproject.com/KB/static/clabel.aspx

If nothing else it will give you some ideas on how to do this sort of thing,
but there is also other functionality you may find useful.

Tom

"JY" <sd(a)nospamgroup.com> wrote in message
news:1F7385C4-1922-46F8-8B69-ED53A8DB70FB(a)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.
>
> CFont fontStatic;
> CFont *pFont = m_StaticText.GetFont();
> CFont *pFontNew = new CFont();
> if (pFont)
> {
> LOGFONT logFont;
> pFont->GetLogFont(&logFont);
> logFont.lfHeight += 30;
>
> pFontNew->CreateFontIndirectW(&logFont);
> m_StaticText.SetFont(pFontNew);
> }
> m_StaticText.SetWindowTextW(L"Static Window Text");
>
> What am I doing wrong?
>
> TIA,
> JY


From: David Ching on
"JY" <sd(a)nospamgroup.com> wrote in message
news:1F7385C4-1922-46F8-8B69-ED53A8DB70FB(a)microsoft.com...
> pFontNew->CreateFontIndirectW(&logFont);
> m_StaticText.SetFont(pFontNew);
> }
> m_StaticText.SetWindowTextW(L"Static Window Text");
>
> What am I doing wrong?
>

After setting the font, call m_StaticText.Invalidate(); setting the same
window text won't cause it to repaint using the new font, if the text is the
same as before.

-- David