Solved

Stop ESC from closing dialog app

Posted on 1998-06-18
4
661 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 55
Login Script to Copy Folders 12 47
Looking for a specific application/software 2 119
string initialization in java 11 117
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.

726 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