int CMyDialogClass::SetDefaultButton(const DWORD nNewId) { DWORD nPrevId = GetDefID(); // Its not automatic - we have to remove the border from the old button SendDlgItemMessage(nPrevId, BM_SETSTYLE, BS_PUSHBUTTON, (LPARAM)TRUE); SetDefID(nNewId); // Likewise, add a border to the new one SendDlgItemMessage(nNewId, BM_SETSTYLE, BS_DEFPUSHBUTTON, (LPARAM)TRUE); return nPrevId; }
Programming Tips - MFC: Set the default button in a dialog when using MFC
Date: 2008jan21
Framework: MFC
OS: Windows
Language: C/C++
Q. MFC: Set the default button in a dialog when using MFC
A. Usually its the "OK" button.
This function does the trick: