Solve the problem of Enter/Esc key crash in MFC program

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);
}
...

Guess you like

Origin blog.csdn.net/weixin_41243045/article/details/88674583