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:
- Void CMyDialog: DoDataExchange (CDataExchange * pDX)
- {
- CDialog: DoDataExchange (pDX); // Call base class version
- DDX_Check (pDX, IDC_MY_CHECKBOX, m_bVar );
- DDX_Text (pDX, IDC_MY_TEXTBOX, m_strName );
- DDV_MaxChars (pDX, m_strName, 20 );
- }
- 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
- 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