Link to home
Start Free TrialLog in
Avatar of ijkl
ijkl

asked on

problem with modeless!...

hi!
my main application is a dialog based app.i created a modeless dialog box as below
BOOL CMDApp::InitInstance()
{
AfxEnableControlContainer();
#ifdef _AFXDLL
  Enable3Controls();
#else
 Enable3ControlsStatic();
#endif
 CMDDlg *dlg= new CMDDlg;
 dlg->Create();
 m_pMainWnd = dlg;
 return TRUE;
}
i destroyed it using..
void CMDDlg::OnCancel()
{
  CMDDlg::DestroyWindow();
}

now my problem is that when the user presses the ESC key the dialog box vanishes.i want the dialog box to stay.
how can modify this?..what is the reason for the dialog box to vanish even after overriding the OnCancel() function?
Avatar of ijkl
ijkl

ASKER

Adjusted points from 50 to 100
As you mentioned ESC invokes OnCancel.

Remove the DestroyWindow from OnCancel - leaving the handler blank.



If you remove the "CMDDlg::DestroyWindow();" from the code, then your dialog should not close when Esc is pressed.

You should use:

void CMDDlg::OnCancel()
{
}

to destroy it instead.
Toad

I hate to ask this...but your answer differs from mine how?
As an alternative - if you wish **just** to disable the Escape key...

BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
      if (pMsg->message == WM_KEYDOWN)
      {
            if (pMsg->wParam == VK_ESCAPE)
            {
                  return TRUE;
            }
      }
      return CDialog::PreTranslateMessage(pMsg);
}
Avatar of ijkl

ASKER

I tried to do that but it is givig the error as
'PreTranslateMessage' : overloaded member function 'int (struct tagMSG *)' not found in 'CTestDlg'

!

ASKER CERTIFIED SOLUTION
Avatar of MT_MU
MT_MU

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ijkl

ASKER

the method given by Toad224 is not working for my purpose.
i want the dialog box to close when clicked cancel but stay when ESC is pressed!
thanx anyway..
Avatar of ijkl

ASKER

Mt Mu thanx it is working now...i appreciate it..
ijkl..:-)
Avatar of ijkl

ASKER


i already added a comment MT MU ...:-)
thanx..