Click here to Skip to main content
15,886,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
	LOGFONT LogFont;
	CFont * pCurFont=GetFont();//Dialog's Font
	if(!pCurFont) return;
	pCurFont->GetLogFont(&LogFont);
	LogFont.lfWeight=(bBold?FW_BOLD:FW_NORMAL);
	CFont font;
	font.CreateFontIndirect(&LogFont);
	pWndSel->SetFont(&font);

I have a Button in Dialog,When I first Setfont() for it with bBold==True.The Font of the Button 's font is Bold,But when I want to recover it with bBold==false later.
It doesn't work!
Any help?
pWndSel=GetDlgItem(IDC_BNT_SEL_WALL)
Posted
Updated 3-Jul-12 23:29pm
v3
Comments
Soheera 4-Jul-12 6:40am    
bBold == True OR bBold = True?

1 solution

I belive the problem is that you are giving your button a font that is "stored" in a local variable.
Quote:
CFont font;
font.CreateFontIndirect(&LogFont);
pWndSel->SetFont(&font);
-when font goes out of scope, its destructor deletes the font resource. When the button gets redrawn, it will revert to using the system font, which kinda looks bold. So you will see the button's text becoming bold and will think you did ok. Then when you try to set it back to non-bold, you probably do the very same thing, create a local non-bold font object and specify it for your button, but again, when this goes out of scope, it gets destroyed and the button will again use the system font, so you will see that it didn't become "not bold".
Try rewriting your code so the CFont object you want to use with your button remains existent during the lifetime of your button.

Does this help?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900