Solved

Stop ESC from closing dialog app

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
configuration management 2 100
VB.NET how to use the Vertical ScrollBar 5 87
ORA-01403: no data found 43 83
sum67 challenge 35 89
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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

12 Experts available now in Live!

Get 1:1 Help Now