?
Solved

Stop ESC from closing dialog app

Posted on 1998-06-18
4
Medium Priority
?
666 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Accepted Solution

by:
igroove earned 140 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

762 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