Skip to content

Instantly share code, notes, and snippets.

@botaor
Last active December 15, 2015 00:08
Show Gist options
  • Save botaor/5170223 to your computer and use it in GitHub Desktop.
Save botaor/5170223 to your computer and use it in GitHub Desktop.
In Windows MFC if you have a dialog based application, do not exit it with <enter> or <esc>.
class CMyDlg : public CDialog
{
....
protected:
afx_msg void OnCancel();
afx_msg void OnOK();
afx_msg void OnClose();
afx_msg void OnMyExit();
....
};
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
....
ON_WM_CLOSE()
....
END_MESSAGE_MAP()
void CMyDlg::OnOK()
{
// We do not want to close in this situation
}
void CMyDlg::OnCancel()
{
// We do not want to close in this situation
}
void CMyDlg::OnClose()
{
CDialog::OnCancel();
}
void CMyDlg::OnMyExit()
{
OnClose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment