Click here to Skip to main content
15,309,563 members
Please Sign up or sign in to vote.
4.60/5 (5 votes)
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.


See here.

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!
U can add minimize/maximize button on top of the dialog box from the property of the dialog box.

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900