Solve the problem of Enter/Esc key crash in MFC program
Overload the two functions OnOK&OnCancel of CDialog, and overload the processing function of the WM_CLOSE message, calling EndDialog(IDCANCEL) in it
...
class CUSBTOFDDlg : public CDialog
{
...
protected:
virtual void OnOK();
virtual void OnCancel();
afx_msg void OnClose();
...
}
...
...
BEGIN_MESSAGE_MAP(CUSBTOFDDlg, CDialog)
ON_WM_CLOSE()
END_MESSAGE_MAP()
...
...
void CUSBTOFDDlg::OnOK()
{
}
void CUSBTOFDDlg::OnCancel()
{
}
void CUSBTOFDDlg::OnClose()
{
EndDialog(IDCANCEL);
}
...