MFC provides two methods for data exchange and data check (Dialog data exchange/Dialog data validation) in the Dialog box ), the idea of data exchange and data check is to associate a variable with a subwindow in the dialog box, and then call BOOL UpdateData (BOOL bSaveAndValidate = TRUE) to indicate whether MFC puts the data in the variable into the subwindow or retrieves the data in the subwindow to the variable and checks the validity.
During data exchange, a subwindow can be associated with two types of variables (Control) object. For example, a button subwindow can be associated with a CButton object. In this case, you can directly Control the subwindow through this object, instead of using GetDlgItem (IDC_CONTROL_ID) to get the window pointer as described in the previous section. One is the content object. For example, the input box can be associated with a CString object, it can also be associated with a UINT type variable. In this case, you can directly set/obtain the input content in the window.
Data check checks the validity of the content when it is accessed when a subwindow is associated with a content object. For example, when an input box andWhen you associate a CString object, you can set the Maximum/minimum length of the CString object. When the input box is associated with a UINT variable, you can set the Maximum/minimum value of the UINT variable. After BOOL UpdateData (BOOL bSaveAndValidate = TRUE) is called, The validity check is automatically performed. If you cannot pass the check of MFC, a message box is displayed, prompting you to return FALSE.
SetDDX/DDV is very simple in VC. ClassWizard can do all the work for you. You only need to open ClassWizard and select the Member Variables page,,
You can see all the subwindows that can be associated.ID list. Double-click an ID to display a dialog box for adding variables,,
Enter the relevant information and press OK. Then, select the variable you just added and enter the check conditions in the input box at the bottom,.
The following is an example of a subwindow in the dialog box.Settings.The following table lists the IDs and associated variables:
ID
Associated Variables
Function
IDC_CHECK_TEST
BOOL m_fCheck
Check box selected
IDC_RADOI_TEST_1
Int m_iSel
Index of the currently selected Circle button
IDC_COMBO_TEST
CString m_szCombo
Text selected in the combo box or input text
IDC_EDIT_TEST
CString m_szEdit