Click here to Skip to main content
12,956,173 members (106,870 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi experts,

I have an Application in MFC using single dialog window.

Problem i am facing is, it exits when i press escape key.

i want it to exit when i press "Exit" button that i made my self and also by pressing "x"(default close button provided in dialog) button on top right corner of window but not by "esc" key.

I tried emptying the implementation of "OnCancel" function. It solves the problem of "esc" key, but it also disables, exit when i press "x" button.

Please help me, it is very annoying when i accidentally press exit and window goes away.

If possible, tell me way to add, minimize button along with "x"(close) button on the top.

Posted 8-Aug-09 9:11am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

See here.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Also, one use use PreTranslateMessage to intercept the ESC key. Add the function to the dialog using the class wizard, then check for the ESC key.

BOOL CDxf2NastranDlg::PreTranslateMessage(MSG* pMsg) <br />{<br /> // TODO: Add your specialized code here and/or call the base class<br /> // ESC key<br /> if(pMsg->wParam == VK_ESCAPE) { return TRUE; }<br /><br /> return CDialog::PreTranslateMessage(pMsg);<br />}<br />
Jörgen Sigvardsson 1-Oct-10 18:28pm
Now that's using a sledge hammer to drive in a nail!
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

U can add minimize/maximize button on top of the dialog box from the property of the dialog box.
    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,243
ppolymorphe 2,070
Jochen Arndt 1,973

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 13 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100