Reputation: 23
When the dialog is opened and the escape key is pressed, a button click event is firing, the dialog should dismiss not run the event.
I have inspected the Resources file in notepad to see what is happening, I have commented out the button in the message map, the issue goes away. I have no idea why this happening and I cannot find any presets in my code that would cause this to happen
Here is the Dialog in the Resources file
IDD_SVGDLG DIALOGEX 0, 0, 675, 462
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Export to File",IDC_SVYDLG_EXPORT,173,431,62,24
END
Here is the message map...
BEGIN_MESSAGE_MAP(CSurveyDlg, CDialogEx)
ON_BN_CLICKED(IDC_SVYDLG_EXPORT, &CSurveyDlg::OnBnClickedExport)
END_MESSAGE_MAP()
I expect the dialog to dismiss, export should only run when the button is clicked
Upvotes: 1
Views: 206
Reputation: 31629
If IDC_SVYDLG_EXPORT
is defined as 2, it will be the same value as IDCANCEL
, and the button will respond to Escape key to cancel the dialog.
ID numbers from 1 to 7 are reserved for standard buttons, IDOK, IDCANCEL, ...
It's recommended to use numbers in the range 100
up to 0x7000
for controls. MFC dialog editor may generate its own numbers in this range.
See also ID Naming and Numbering Conventions
Upvotes: 2