
| Last Modification: February 27, 2000 |
How can I make the ENTER key act like the TAB key on a dialog?
You can do this by either overriding OnOK() or PreTranslateMessage()
If you do the former, check the ID of the control that
currently has the focus (you need to do this to ensure you can still press ENTER to
press the OK button) and call NextDlgCtrl(). If you do the latter, you have to watch
for WM_KEYDOWN messages and a VK_ENTER key.
Here's an example of the first technique:
void CMyDlg:: OnOK()
{
CWnd *pWnd = GetFocus();
ASSERT (pWnd);
if (IDOK == pWnd ->GetDlgCtrlID())
{
CDialog::OnOK();
}
else
{
NextDlgCtrl();
}
}
One thing to note, though, is that doing this is "unnatural" in the windows world, and goes again the Windows User Interface Development Guidelines. As such, it goes against most windows applications, and can potentially confuse or frustrate the user.