Article ID: 102589
Article Last Modified on 7/11/2005
case WM_COMMAND:
if(wParam=IDOFDEFBUTTON || IDOK) {
// User has hit the ENTER key.
hwndTest = GetFocus() ;
retVal = TesthWnd(hWndTest) ;
//Where retVal is a boolean variable that indicates whether
//the hwndTest is the handle of one of the edit controls.
if(hwndTest) {
//Focus is with an edit control, so do not close the dialog.
//Move focus to the next control in the dialog.
PostMessage(hDlg, WM_NEXTDLGCTL, 0, 0L) ;
return TRUE ;
}
else {
//Focus is with the default button, so close the dialog.
EndDialog(hDlg, TRUE) ;
return FALSE ;
}
}
break ;
//*-------------------------------------------------------------------
//| Title:
//| SubClassProc
//|
//| Parameters:
//| hWnd - Handle to the message's destination window
//| wMessage - Message number of the current message
//| wParam - Additional info associated with the message
//| lParam - Additional info associated with the message
//|
//| Purpose:
//| This is the window procedure used to subclass the edit control.
//*---------------------------------------------------------------------
long FAR PASCAL SubProc(HWND hWnd, WORD wMessage,WORD wParam,LONG
lParam)
{
switch (wMessage)
{
case WM_GETDLGCODE:
return (DLGC_WANTALLKEYS |
CallWindowProc(lpOldProc, hWnd, wMessage,
wParam, lParam));
case WM_CHAR:
//Process this message to avoid message beeps.
if ((wParam == VK_RETURN) || (wParam == VK_TAB))
return 0;
else
return (CallWindowProc(lpOldProc, hWnd,
wMessage, wParam, lParam));
case WM_KEYDOWN:
if ((wParam == VK_RETURN) || (wParam == VK_TAB)) {
PostMessage (ghDlg, WM_NEXTDLGCTL, 0, 0L);
return FALSE;
}
return (CallWindowProc(lpOldProc, hWnd, wMessage,
wParam, lParam));
break ;
default:
break;
} /* end switch */
protected:
virtual void OnOK();
Add an OnOK function to the dialog box and code is as demonstrated below:
void CMyDialog::OnOK()
{
CWnd* pwndCtrl = GetFocus();
CWnd* pwndCtrlNext = pwndCtrl;
int ctrl_ID = pwndCtrl->GetDlgCtrlID();
switch (ctrl_ID) {
case IDC_EDIT1:
pwndCtrlNext = GetDlgItem(IDC_EDIT2);
break;
case IDC_EDIT2:
pwndCtrlNext = GetDlgItem(IDC_EDIT3);
break;
case IDC_EDIT3:
pwndCtrlNext = GetDlgItem(IDC_EDIT4);
break;
case IDC_EDIT4:
pwndCtrlNext = GetDlgItem(IDC_EDIT1);
break;
case IDOK:
CDialog::OnOK();
break;
default:
break;
}
pwndCtrlNext->SetFocus();
}
Additional query words: push RETURN keydown
Keywords: kbhowto kbdlg kbeditctrl kbctrl KB102589