IDCANCEL is defined by windows to have the value 2. But I need to define something else to the value 2 to be used in WM_COMMAND. Most of the code you see online uses EndDialog in WM_COMMAND. Could I use EndDialog in WM_CLOSE instead like this?
case WM_CLOSE:
EndDialog(hwndDlg, IDCANCEL);
break;
If this is a custom message box then yes, you can assign any value you want to the button. But the second parameter in "EndDialog()" will be the value returned to the parent window so that's the value you want to change.
But I need to define something else to the value 2 to be used in WM_COMMAND.
Out of interest, what needs to have the value of 2?
If possible, it would be better to leave IDCANCEL and the like alone (for reasons of consistency if nothing else) and apply an offset to your IDs.
For example, it you were coding a caculator you could assign the numeric buttons IDs' of 2000, 2001, ... 2009 (for 0..9) and then subtract 2000 when you handle the command.
Could I use EndDialog in WM_CLOSE instead like this?
WM_CLOSE will work if you're just closing the dialog by either clicking on the [x] button or the "Close" item in the system menu.