开发者

Escape key not closng the Dialog

开发者 https://www.devze.com 2023-03-14 04:08 出处:网络
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 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 CPr开发者_如何学GoopertyPage
       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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消