Escape 键不关闭对话框
我看过很多关于如何防止转义键关闭 CDIAlog 的帖子,但就我而言,我想关闭对话框,但它没有。
我创建了一个示例 MFC 对话框应用程序,它添加了属性表和 2 个属性页。我尝试将 pretranslatemessage、OnCancel、KillFocus 覆盖放入属性页和对话框中,但没有成功。 使用以下代码:
#include "proppage1.h"
#include "proppage2.h"
#include "mySheet.h"
// ......
protected:
// proppage1,proppage2 are the class dervied from CPropertyPage
proppage1 pg1;
proppage2 pg2;
// mySheet is the class dervied from CPropertySheet
mySheet *m_sheet;
在 MFCDlg.CPP 的 CMFCDlg::OnInitDialog() 中
m_sheet = new mySheet(L"mySheet",this,0);
m_sheet->AddPage(&pg1);
m_sheet->AddPage(&pg2);
m_sheet->Create(this, WS_CHILD | WS_VISIBLE , 0);
m_sheet->ModifyStyleEx (0, WS_EX_CONTROLPARENT);
m_sheet->ModifyStyle( 0, WS_TABSTOP );
,我没有在属性页和对话框中触发任何事件。 如果我在属性页上放置一些控件,则会触发事件并可以在属性页中捕获事件。 但是,在其他情况下,为什么 Esc 和其他事件不会被触发?
请建议?
谢谢, 尼基尔
I have seen so many posts about how to prevent the escape key from closing a CDIalog but in my case I want to close the dialog but it doesn`t.
I have created a sample MFC Dialog application thats adds property sheet and 2 property pages. I tried putting pretranslatemessage, OnCancel, KillFocus overrides into the property pages and the dialog but that doesn't get hit.
Used following code:
#include "proppage1.h"
#include "proppage2.h"
#include "mySheet.h"
// ......
protected:
// proppage1,proppage2 are the class dervied from CPropertyPage
proppage1 pg1;
proppage2 pg2;
// mySheet is the class dervied from CPropertySheet
mySheet *m_sheet;
In CMFCDlg::OnInitDialog() of MFCDlg.CPP
m_sheet = new mySheet(L"mySheet",this,0);
m_sheet->AddPage(&pg1);
m_sheet->AddPage(&pg2);
m_sheet->Create(this, WS_CHILD | WS_VISIBLE , 0);
m_sheet->ModifyStyleEx (0, WS_EX_CONTROLPARENT);
m_sheet->ModifyStyle( 0, WS_TABSTOP );
I dont get any events fired in propertypages and dialog.
If I place some controls on the property pages, then events are fired and can be catched in property pages.
However,in other case why wouldn't the Esc and other event get fired?
Please suggest?
Thanks,
Nikhil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信 pg1 和 pg2 都是 CPropertyPage 类型或派生类的对象。如果它们是
CDialog
或派生对象,则可能无法工作 - 确保消息映射正确映射到CPropertyPage
而不是CDialog
此外,还有无需为
CPropertySheet
对象调用Create
。构造函数做这件事。您在哪里调用DoModal
或ShowWindow
?如果您正在调用CPropertySheet::DoModal
,则无需在堆上分配属性表。我会简单地使用:
I believe both
pg1
andpg2
are objects of typeCPropertyPage
or derived class. If they areCDialog
or derived objects, it may not work - ensure the message-map is correctly mapped withCPropertyPage
and notCDialog
Further, there is no need to call
Create
for aCPropertySheet
object. Constructor does the thing. Where are you callingDoModal
orShowWindow
? If you are callingCPropertySheet::DoModal
, there is no need to allocate property-sheet on heap.I would have simply used:
在属性表中,您可以捕获 WM_KEYDOWN 消息并检查转义
In your property sheet, you can capture the WM_KEYDOWN message and check for escape