Click here to Skip to main content
11,488,646 members (76,633 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 4-Jul-12 0:27am
Edited 4-Jul-12 0:29am
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 Sergey Alexandrovich Kryukov 489
1 OriginalGriff 328
2 Mehdi Gholam 145
3 Sascha Lefèvre 135
4 KarstenK 115
0 Sergey Alexandrovich Kryukov 9,308
1 OriginalGriff 8,352
2 Sascha Lefèvre 3,334
3 Maciej Los 2,956
4 Richard Deeming 2,370

Advertise | Privacy | Mobile
Web04 | 2.8.150520.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