对话框setFont中的按钮无法撤消 [英] Button in Dialog setFont cann't revover

查看:83
本文介绍了对话框setFont中的按钮无法撤消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

	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);


我在对话框中有一个Button,当我第一次使用bBold == True为其设置Setfont()时,Button的字体为Bold,但是稍后我想使用bBold == false来恢复它时.
它不起作用!
有帮助吗?
pWndSel = GetDlgItem(IDC_BNT_SEL_WALL)


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)

推荐答案

我相信问题是,您给按钮提供了一种存储在"按钮中的字体局部变量.
I belive the problem is that you are giving your button a font that is "stored" in a local variable.
报价:

CFont字体;
font.CreateFontIndirect(& LogFont);
pWndSel-> SetFont(& font);

CFont font;
font.CreateFontIndirect(&LogFont);
pWndSel->SetFont(&font);

-当font超出范围时,其析构函数将删除字体资源.重绘按钮后,它将恢复为使用系统字体,该字体看上去有点黑体.因此,您将看到按钮的文本变为粗体,并认为您没问题.然后,当您尝试将其设置为非粗体时,您可能会做同样的事情,创建一个本地非粗体字体对象,并为您的按钮指定它,但是再次,当它超出范围时,它将被破坏并该按钮将再次使用系统字体,因此您将看到它没有变成非粗体".
尝试重新编写代码,以便要在按钮的生命周期内保留要与按钮一起使用的CFont对象.

这有帮助吗?

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


这篇关于对话框setFont中的按钮无法撤消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆