Link to home
Start Free TrialLog in
Avatar of ducksoup
ducksoup

asked on

move from one editbox to another automatically(SDI)

I am trying to use two editboxes to hold a scanned in nine character ( 4 )-( 5 )control number.  I can't seem to find any info on automatically moving from one editbox to the next.  I thought I could some-how link the tab sequence on the controls in the SDI I am using.....?  I would greatly appreciate any help you could give me (a direction to point me in).  Thanks for your time.
Avatar of thresher_shark
thresher_shark

Would SetFocus fullfill your needs?  You might want to look into it, it is a member function of the CWnd class.  The way you could implement it would be something like:

1) Wait for edit box one to get filled up to 4 characters.
2) Once the limit is reached, use SetFocus to set the focus to the second edit box.

You can pass GetDlgItem (IDC_IDOFEDITBOX2)'s return value to the SetFocus function.

If you have further questions on how to implement this, please feel free to ask.  Thanks!
You could also use WM_NEXTDLGITEM...
Oops that should be WM_NEXTDLGCTL
Use SetFocus as thresher suggested

Each edit control sends an EN_CHANGE notification to the parent window when it's contents change, use this to know when to move between controls.

Either

GetDlgitem( ID_EDIT ) -> SetFocus() ;

or

::SetFocus( ::GetDlgItem(m_hWnd,ID_EDIT) ) ;
Use SetFocus as thresher suggested

Each edit control sends an EN_CHANGE notification to the parent window when it's contents change, use this to know when to move between controls.

Either

GetDlgitem( ID_EDIT ) -> SetFocus() ;

or

::SetFocus( ::GetDlgItem(m_hWnd,ID_EDIT) ) ;
Perhaps I should "Answer" ?
Perhaps I should "Answer" ?
I think you should thresher_shark. You have started as a comment which is in the right direction.
Yep thresher
ASKER CERTIFIED SOLUTION
Avatar of thresher_shark
thresher_shark

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ducksoup

ASKER

thresher_shark, could you give me a little more info on SetFocus(), I researched this function but can't seem to get the syntax correct.  I have tried somethings but I am still struggling, here is one of the things I have tried.
      if (m_strControlNum1.GetLength() == 4) {
            SetFocus()->GetDlgItem(IDC_EDIT2);
            //CWnd *pEdit2 = GetDlgItem(IDC_EDIT2);
            //GotoDlgCtrl(pEdit2);
                  CDialog::OnOK();
          }
   This will compile and run with no effect on the cursor position.  Some of the other things I have tried won't compile.  Thanks for any help
Sure no problem.  What you want to do is add a handler for when the first edit box is updated like so:

void CYourDlg::OnChangeWhatever ()
{ UpdateData (TRUE); // Update numbers in variables.

  if (m_strControlNum1.GetLength () == 4)  // If 4 chars full
  { ::SetFocus (m_strControlNum2.GetSafeHwnd ()); // Set focus
    m_strControlNum1.SetSel (0, -1);  // Remove selection
  }
}

Also, one other note (for the future), you do not want to "accept" someone's answer until they have followed through completely with the solution.  Often the answers are vague and require clarification.  If that is the case either reject the answer or request clarification before awarding the points.  You see, some people will just answer and not follow through with it at all.

In any case, does that solve your problem?  If you have any other questions, please ask.  Thanks!
Well done, thresher. Keep up the good work.