Data exchange in the VC ++ dialog box [perfect]

Source: Internet
Author: User

If the DDX mechanism is used, the initial values of the member variables of the dialog box are usually set in the OnInitDialog handler or dialog box constructor. Before the dialog box is displayed, the ddx mechanism of the framework transfers the value of the member variable to the control in the dialog box. When the dialog box itself appears in response to DoModal or Create, these values are displayed in the dialog box.

By default, OnInitDialog in CDialog calls the UpdateData member function of the CWnd class to initialize controls in the dialog box. When you click the "OK" button or call the UpdateData member function with the parameter TRUE at any time, this mechanism also transfers the value of the control to the member variable. In the dialog box, the data verification mechanism verifies any data items that you specified the verification rule. As specified by the BOOL parameter passed to it, UpdateData performs bidirectional exchange. To perform the exchange, UpdateData sets the CDataExchange object and calls the dialog box class to override the DoDataExchange member function of CDialog. DoDataExchange uses CDataExchange parameters. The CDataExchange object passed to UpdateData indicates the context of the exchange, which defines the exchange direction and other information. When you or a code wizard) override DoDataExchange, a DDX function call is specified for each data member control. UpdateData passes a CDataExchange parameter to your DoDataExchange. Each DDX function knows how to exchange data in two directions based on the context provided by this parameter. MFC provides many DDX functions for different exchange types. The following example shows a DoDataExchange rewrite. Two DDX functions and one DDV function are called:
 
 
  1. Void CMyDialog: DoDataExchange (CDataExchange * pDX)
  2. {
  3. CDialog: DoDataExchange (pDX); // Call base class version
  4. DDX_Check (pDX, IDC_MY_CHECKBOX, m_bVar );
  5. DDX_Text (pDX, IDC_MY_TEXTBOX, m_strName );
  6. DDV_MaxChars (pDX, m_strName, 20 );
  7. }
  8. DDX _ rows and DDV _ rows are data ing. The displayed example DDX and DDV functions are used for the check box control and the edit box control respectively. If you cancel the mode dialog box, the OnCancel member function terminates the dialog box and DoModal returns the IDCANCEL value. In this case
  9. The dialog box and dialog box objects do not exchange any data.

This article from the "Yi fall Dusk" blog, please be sure to keep this source http://yiluohuanghun.blog.51cto.com/3407300/1097056

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.