SetFont for CWnd class [modified]
-
I have a class derived from CWnd (it looks like a label). I want to set the font but the following has no effect.I tried setting from within the class, and also externally (below). Neither matters.
LOGFONT lf; // Used to create the CFont.
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 6; // Request a 6-pixel-high font
strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
m_font.CreateFontIndirect(&lf); // Create the font.m_grph.SetFont(&m_font);
:confused: sb -- modified at 15:35 Wednesday 14th June, 2006
-
I have a class derived from CWnd (it looks like a label). I want to set the font but the following has no effect.I tried setting from within the class, and also externally (below). Neither matters.
LOGFONT lf; // Used to create the CFont.
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 6; // Request a 6-pixel-high font
strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
m_font.CreateFontIndirect(&lf); // Create the font.m_grph.SetFont(&m_font);
:confused: sb -- modified at 15:35 Wednesday 14th June, 2006
Does
m_font
belong to theCWnd
-derived class? From where isSetFont()
being called? There is an example in the Extras section of this article.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
I have a class derived from CWnd (it looks like a label). I want to set the font but the following has no effect.I tried setting from within the class, and also externally (below). Neither matters.
LOGFONT lf; // Used to create the CFont.
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 6; // Request a 6-pixel-high font
strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
m_font.CreateFontIndirect(&lf); // Create the font.m_grph.SetFont(&m_font);
:confused: sb -- modified at 15:35 Wednesday 14th June, 2006
-
I have a class derived from CWnd (it looks like a label). I want to set the font but the following has no effect.I tried setting from within the class, and also externally (below). Neither matters.
LOGFONT lf; // Used to create the CFont.
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 6; // Request a 6-pixel-high font
strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
m_font.CreateFontIndirect(&lf); // Create the font.m_grph.SetFont(&m_font);
:confused: sb -- modified at 15:35 Wednesday 14th June, 2006
im not sure your problem is this but m_font is global or no i saw if (m_font) isnt global it doesnt work i wrote a program and used like your code but font dosent change then i changed declare my variable from function to class and it worked._**
**_
whitesky
-
Can you try CreatePointFont?????? The procedure is like this. // member CFont m_FontArial; // Create the font in Constructor m_FontArial.CreatePointFont( 140, PSIGL_CONTROL_FONT_TYPE_ARIAL ); pWindow->SetFont( &m_FontArial ); yours faithfully ajeeshcv
Here is what worked for me:
CClientDC dc(this);
CFont l_font;
l_font.CreateFont(14, 0, 0, 0, FW_NORMAL,
FALSE, FALSE, FALSE, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, "Times New Roman");CFont* l_old_font = dc.SelectObject(&l_font); dc.TextOut(50, 50, "Hello World");
dc.SelectObject(l_old_font);
// Delete the font object.
l_font.DeleteObject();except that I got my CDC in the OnraseBackground function of the CStatic class. Thanks everyone for helping. sb