Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dialog: Keeping the focus

Status
Not open for further replies.

ihirst

Programmer
Aug 27, 2003
2
GB
I want to validate the input into MY_CEdit object. Borland C++ provided a TValidator class but I believe that in Visual C++ there is no equivelent class and you need to write your own code.

In order to do this I need to prevent by control MY_CEdit from loosing the focus. Can some one please point me in the right direction as to how to do this?

Please note I am not greatly experianced in windows programming.
 
I don’t understand what your asking. To keep the focus on an Edit control you handle the EN_KILLFOCUS message for the control and then set the focus. Here is a small example in MFC where the dialog handles the EN_KILLFOCUS message and the dialog member variable _edOne is a MFC CEdit object that subclasses the edit control on the dialog.
Code:
void CMainDlg::OnEnKillfocusEdit1()
{
	CWnd* pEd = (CEdit*)GetDlgItem(IDC_EDIT1);
	if(pEd && !pEd->GetWindowTextLength())
		pEd->SetFocus();
}

>> I am not greatly experianced in windows programming.

I strenuously recommend getting a book targeting beginners for Windows C++ development.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top