Click here to Skip to main content
11,644,286 members (70,129 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ MFC GDI
	CFont * pCurFont=GetFont();//Dialog's Font
	if(!pCurFont) return;
	CFont 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?
Posted 3-Jul-12 23:27pm
Edited 3-Jul-12 23:29pm
Soheera at 4-Jul-12 6:40am
bBold == True OR bBold = True?

1 solution

Rate this: bad
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.
CFont 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?

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

  Print Answers RSS
0 OriginalGriff 650
1 494
2 Afzaal Ahmad Zeeshan 423
3 Sergey Alexandrovich Kryukov 409
4 CPallini 352
0 OriginalGriff 925
1 DamithSL 636
2 Afzaal Ahmad Zeeshan 622
3 Sergey Alexandrovich Kryukov 548
4 CPallini 521

Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 4 Jul 2012
Copyright © CodeProject, 1999-2015
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