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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CEdit input checking

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0

Hi,

I've created an edit box (MFC) and a DDX variable as an integer. Using Class Wizard I've set the Min and Max values. If the user inputs a value outside the Min and Max a message box appears indicating the user must enter a value between Min and Max. This message box was not created by me. Class Wizard must have added it. I would like to gain cotrol and create my own message box. Does anyone know what member function or event I can over ride after the error checking is done.

Thanks in advance,

Brother C
 
Brother C,

Not sure you can override the MsgBox because i believe it is generated from ...Mfc\Src\Dlgdata.cpp. However, one approach would be to create your own error trapping by eliminating the range you entered in the class wizard. Then add a member function (you can do this thru the class wizard as well) OnKillFoucs(). Then get the value that was entered, check the data if it is not valid display your custom message box then set the focus back to the edit contol. I'm sure there are other more graceful ways but this will work.
void CTempDlg::OnKillfocusEdit()
{
int x = GetDlgItemInt(IDC_EDIT_NAME, NULL, TRUE);

if (x < Min || x > Max)
{
MessageBox(&quot;Your Message&quot;, MB_OK);
m_ctlEdit_NAME.SetFocus();
m_ctlEdit_NAME.SetSel(0,-1);
}
}

HTH,
JC [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top