MFC C++ VC 2010.
I have a dialog problem that is driving me nuts. I have a dialog that is sort of a version of AfxMessageBox with some added features. The default button needs to be settable and I can't seem to get that to work.
My .rc file looks like this
IDD_DLG_GENMSG DIALOGEX 0, 0, 240, 95
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Static",IDC_GM_TXTMSG,41,7,192,62
ICON "",IDC_GM_ICOMSG,18,10,20,20,0,WS_EX_TRANSPARENT
PUSHBUTTON "OK",IDC_GM_BTNLEFT,68,74,50,14
PUSHBUTTON "Cancel",IDC_GM_BTNRIGHT,122,74,50,14
PUSHBUTTON "Abort",IDC_GM_BTNABORT,41,74,50,14
PUSHBUTTON "Retry",IDC_GM_BTNRETRY,95,74,50,14
PUSHBUTTON "Ignore",IDC_GM_BTNIGNORE,149,74,50,14
END
At start I enable of disable buttons as needed and the text on the button is changed programmatically as needed. No matter what I do, the first button listed in the resource file is always the default.
I tried a couple of methods described in these links
https://forums.codeguru.com/showthread.php?197179-Switching-Default-Buttons-MFC
https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/67655
As I said, not this always had the first listed button as the default when I hit Return. As a work around I implemented a PreTranslateMessage override, but it never received the WM_KEYDOWN message and WK_RETURN key.
BOOL CDlgGenMsg::PreTranslateMessage(MSG* pMsg)
{
ASSERT(pMsg != NULL);
ASSERT_VALID(this);
ASSERT(m_hWnd != NULL);
if((pMsg->message == WM_KEYDOWN))
{
if(pMsg->wParam == VK_RETURN)
{
}
}
return(CDialog::PreTranslateMessage(pMsg));
}
What I have tried:
Detailed above in the body.
I'm probably missing something simple, but it's got me stumped.