Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC GDI
	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 3-Jul-12 23:27pm
Edited 3-Jul-12 23:29pm
v3
Comments
Soheera at 4-Jul-12 6:40am
   
bBold == True OR bBold = True?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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?
  Permalink  

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

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 OriginalGriff 394
2 thatraja 370
3 Sergey Alexandrovich Kryukov 334
4 CPallini 219
0 OriginalGriff 697
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 495
3 thatraja 370
4 Sergey Alexandrovich Kryukov 344


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 4 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100