Solved

Stop ESC from closing dialog app

Posted on 1998-06-18
4
660 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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 to retreive data from .TFS file exported by DVR 8 217
string initialization in java 11 115
fizzArray2 challenge 1 89
Modbus - whats the maximum I can store in one register? 4 80
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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