DoModal( ) function creates and displays the dialog box. Just after creation of the dialog box and before displaying it Windows sends the dialog box WM_INITDIALOG message. This message activates OnInitDialog( ) handler. In this handler we should call base class’s OnInitDialog( ) because it calls CWnd::UpdateData( ) function with a FALSE parameter. UpdateData( ) in turn creates a CDataExchange object and calls dialog class’s DoDataExchange( ), passing it a pointer to CDataExchange object. In this function macros like DDX_Text( ), DDX_Check( ) etc. are used to initialize a control to the value of the dialog box when it is displayed.
If we wish to extract data from the controls or validate the data we must override OnOK( ) handler. In our implementation we must call CDialog‘s OnOK( ) function. When the user clicks OK, OnOK( ) handler calls UpdateData( ) with TRUE parameter. So when DoDataExchange( ) is called values entered in the controls get collected in the associated variables. OnOK( ) calls EndDialog( ) functions to dismiss the dialog box.