Link to home
Start Free TrialLog in
Avatar of gregga
gregga

asked on

Stop ESC from closing dialog app

I am building a dialog-based application that needs to be shutdown with some smarts.  I now find that the Esc Key drops it immediately drops out.  How do I trap this key?  I am new to VC++ programming, a couple of weeks into it.
ASKER CERTIFIED SOLUTION
Avatar of igroove
igroove

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

Try  to use something like this.
1.member function ONCancel ,Create from Class wizard

void CMyDlg:: OnCancel()
{
      CWnd *pWnd = GetFocus();
      ASSERT (pWnd);
      if (IDCANCEL == pWnd ->GetDlgCtrlID())
      {
                 //your code
                  .....
                  return;
      //don,t call it      
                   CDialog::OnCancel();
      }
      else
      {
            //your code;
      }
}
Rename the Id of the cancel Button as IDCANCEL1 and write a function for IDCANCEL1 using the ClassWizard for BN_CLICKED command.

In OnCancel1( )
{
   CDialog::OnCancel( );
}

Also, in the header file of u'r dialog , have a prototype for the function OnCancel( )

as void OnCancel( )

and in the source file

void OnCancel( )
{
   // do nothing
}

This should prevent the default behaviour of the Esc button.

Hope this helps.
Avatar of gregga

ASKER

Igroove answer trapped nearly every key but the ESC.
The comment from kalaru solved the problem, How do I grade this?