Navigating from one Edit Control to the Next
I have two Edit Boxes on my Dialog which my user inputs a properly formated date. I.E. DD-MON-YYYY First problem is how can I automatically move the cursor to the 2nd Edit box when the last character has been entered in the first Edit box. Second problem is I am testing to make sure that when the Process Button on the Dialog is pressed that is either of the boxes are empty the user gets a warning to enter a valid date in whichever edit box was empty. Now I would like to know how can I (after this check has been made and the user acknowledges the message box) return focus to the offending edit box? Actually it would be for the 2nd edit box as the problem is that once the Warning Message has be acknowledged it always returns focus to the First Edit Box.
Any assistance especially any code and guidance for where the code goes would be greatly appreciated!
Thanks! Charlie
Re: Navigating from one Edit Control to the Next
did you try this?
....
// after displaying warning dialog
CWnd *pWnd = GetDlgItem(IDC_EDIT2);
if (pWnd)
{
pWnd->SetFocus();
}
....
-Safai
Re: Navigating from one Edit Control to the Next
Firstly, u should do a SendDlgItemMessage(EM_LIMITTEXT) to that control in the WM_INITDIALOG. This will prevent the user from typing in more characters that specified by U.
Then, in the WM_COMMAND meesage, when the contorl's ID is sent, keep checking for EN_CHANGE untill u encounter a EN_MAXTEXT message. On encountering it, set the focus to the next edit box.
switch(message)
{
case WM_INITDIALOG:
SendDlgItemMessage(hDlg, ED_DATE, EM_LIMITTEXT,length, 0);
break;
case WM_COMMAND:
switch(wParam)
{
case ED_DATE:
//u should check for EN_UPDATE or EN_CHANGE, I'm not sure
if(HIWORD(lParam) == EN_CHANGE)
{
//either do a GetDlgItemText here or check for EN_MAXTEXT and set the focus
SetFocus();
}
break;
}
}