Solved

Stop ESC from closing dialog app

Posted on 1998-06-18
4
656 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:gregga
4 Comments
 
LVL 2

Accepted Solution

by:
igroove earned 70 total points
ID: 1318209
Intercept the WM_KEYDOWN message in your dialog class.

Open the Class Wizard, and select your dialog class.  Go to the
Messages Tab in the Wizard.  Select the WM_KEYDOWN message
and add a handler for it.  Close the class wizard and go to
the recently added wizard code for it.  It should be a method
on your class called OnWmKeyDown.

The ascii value of the ESC key is 27.  You'll notice that
the method calls CDialog::OnWmKeyDown().  before this call
you should test for the ESC key.

if (KeyAscii == 27)  return;

That's it.

Also, make sure there are NO command buttons on your dialog
with the "cancel" property set.

0
 

Expert Comment

by:YKunisky
ID: 1318210
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;
      }
}
0
 

Expert Comment

by:kalaru
ID: 1318211
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.
0
 

Author Comment

by:gregga
ID: 1318212
Igroove answer trapped nearly every key but the ESC.
The comment from kalaru solved the problem, How do I grade this?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
Add content to output file 4 62
sumNumber challenge 16 111
post4 challenge 28 93
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now