Prev: Overloaded constructor issues in MFC Dialogs
Next: show Image with CImage - Debug assertion failed
From: JY on 16 Feb 2010 08:41 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 16 Feb 2010 11:55 "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 16 Feb 2010 12:05 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 16 Feb 2010 22:59 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 17 Feb 2010 00:48 "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
|
Next
|
Last
Pages: 1 2 Prev: Overloaded constructor issues in MFC Dialogs Next: show Image with CImage - Debug assertion failed |