Solved

How to not quit an application when ENTER is pressed?

Posted on 2003-11-27
3
247 Views
Last Modified: 2013-11-20
I have created a simple MFC application but I don't want to close the program when the user pressed the Enter key.
I don't know how to change this property.
Can somebody help me out?

I am using VC++ 6.0

Thanks!
0
Comment
Question by:UltimateApocalypse
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 50 total points
ID: 9835621
Overwrite PretranslateMessage in dialog class:

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
    if( pMsg->message == WM_KEYDOWN )
    {
        if( pMsg->wParam == VK_RETURN ||  pMsg->wParam == VK_ESCAPE )  // Enter, Esc
        {
            ::TranslateMessage(pMsg);
            ::DispatchMessage(pMsg);
            return TRUE;
        }
    }
      
      return CDialog::PreTranslateMessage(pMsg);
}
0
 

Author Comment

by:UltimateApocalypse
ID: 9835642
Thanks!
0
 

Expert Comment

by:lucky_boy
ID: 9845040
Hi
I suggest simply to go to the resource editor and in the properties window for the default button, which is OK button by default, to uncheck the "Default button" option. /it is in the "Styles" page /
Good luck
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now