Escape 键不关闭对话框

发布于 2024-11-16 08:01:49 字数 981 浏览 1 评论 0原文

我看过很多关于如何防止转义键关闭 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白芷 2024-11-23 08:01:49
 m_sheet = new mySheet(L"mySheet",this,0);
 m_sheet->AddPage(&pg1);
 m_sheet->AddPage(&pg2);

我相信 pg1 和 pg2 都是 CPropertyPage 类型或派生类的对象。如果它们是 CDialog 或派生对象,则可能无法工作 - 确保消息映射正确映射到 CPropertyPage 而不是 CDialog

此外,还有无需为 CPropertySheet 对象调用 Create。构造函数做这件事。您在哪里调用 DoModalShowWindow?如果您正在调用CPropertySheet::DoModal,则无需在堆上分配属性表。

我会简单地使用:

CPropertySheet sheet( _T("MySheet Title") );
CPropertyPage page1(ID1), page2(ID2);
sheet.AddPage(&page1);
sheet.AddPage(&page2);

sheet.DoModal();
 m_sheet = new mySheet(L"mySheet",this,0);
 m_sheet->AddPage(&pg1);
 m_sheet->AddPage(&pg2);

I believe both pg1 and pg2 are objects of type CPropertyPage or derived class. If they are CDialog or derived objects, it may not work - ensure the message-map is correctly mapped with CPropertyPage and not CDialog

Further, there is no need to call Create for a CPropertySheet object. Constructor does the thing. Where are you calling DoModal or ShowWindow? If you are calling CPropertySheet::DoModal, there is no need to allocate property-sheet on heap.

I would have simply used:

CPropertySheet sheet( _T("MySheet Title") );
CPropertyPage page1(ID1), page2(ID2);
sheet.AddPage(&page1);
sheet.AddPage(&page2);

sheet.DoModal();
拥抱影子 2024-11-23 08:01:49

在属性表中,您可以捕获 WM_KEYDOWN 消息并检查转义

BOOL CInfoPropertySheet::PreTranslateMessage(MSG* pMsg)
{
    switch(pMsg->message)
    {
        case WM_KEYDOWN:
        {
            if( pMsg->wParam == VK_ESCAPE )

In your property sheet, you can capture the WM_KEYDOWN message and check for escape

BOOL CInfoPropertySheet::PreTranslateMessage(MSG* pMsg)
{
    switch(pMsg->message)
    {
        case WM_KEYDOWN:
        {
            if( pMsg->wParam == VK_ESCAPE )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文