Solved

How to not quit an application when ENTER is pressed?

Posted on 2003-11-27
3
250 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
twoTwo  challenge 35 101
sumHeights2  challenge 7 103
How to convert MFC::CString to UTF8 wchar_t* 10 203
Change to event 1 111
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: 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. …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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