CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    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

    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

  2. #2
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    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


  3. #3
    Join Date
    May 1999
    Location
    New Jersey, USA
    Posts
    10

    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;
    }
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured