Perform data exchange and check in the dialog box

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.