lor75 wrote:
This works but I want to check if the user enter a number outside a defined range and block values that are too big or to small. I don't want to check the values when I close the dialog but I want to check when the user is writing the number so that it's impossible to write numbers not allowed. The edit control must show only permitted value.
That Cannot Work! Say, the Minimum accepted Number is 300, and the user wants to input 552. the user starts with typing a 5. This is less than 300, so an Error Message will Occur. You get the Gist. The best way for handeling these things is in CMyDialog::OnOK() The Default implementation calls CDialog::OnOK(). GET RID OF THAT! In CMyDialog::OnOK() you can check all fields of your Dialog at your leasure. Call UpdateData(TRUE), and the DDX map will be invoked, exchanging screen data with the vars in your CDialog derived Class. All variables in the DDX Map will then be updated from the screen. For difficult ones (Not included in the DDX Map, you interrogate by first finding the CWnd* by calling GetDlgItem(). Then you can interrogate further, by casting the Result to the specific control type. (e.g. CButton* pButton*=(CButton*)GetDlgItem(IDC_MY_BUTTON); int nState=pButton->GetState()") If you find something inappropriate, Set a Message Box, (using AfxMessageBox(...) ) to alert the User of the problem, and Return. (As a user service you can also set the focus to the offending Dlg Control.) By returning, the Dlg blijft actief en op het scherm. (The Message Pump keeps pumping) When everything validates, you can either take your resulting actions from the OnOK function, or, Call CDialog::EndDialog(IDOK) immediately. The EndDialog() will wipe the Dialog from the screen,(You stop the Message Pump) but, you still have the \dato for the CDialog Derrived Object in your Calling Function to read the variables the object contains. Hope this helps, :)
Bram van Kampen