, , CDialog, "" :
- (WM_SYSCOMMAND SC_CLOSE)
- Window close events (WM_COMMAND with IDOK or IDCANCEL identifier)
However, MFC effectively routes the old event class through CDialog :: OnCancel by default when they are sent to the dialog box, which means that overriding OnCancel also breaks Alt-F4 and the X button. This means that in order to distinguish between the two, you you need to handle the first events in OnSysCommand, using OnOK and OnCancel overrides to handle the latter.
The resulting code looks something like this:
class CTopLevelDlg: public CDialog
{
afx_win void OnSysCommand(UINT id, LPARAM lparam) override
{
if (id == SC_CLOSE)
CDialog::OnCancel();
}
void OnOK() override {}
void OnCancel() override {}
};
source
share