Dodataexchange is called by the Framework to interact with and verify the dialog box data, mainly implemented by (DDX) and (DDV) macros. Never call this function directly. Instead, use updatedata (true/false) to transfer the value between the control and the variable.
You can also pass the value between the control and the variable without using dodataexchange, for example:
Use functions such as getwindowtext and setwindowtext to complete data interaction between the string variable and the Edit Control.
DDX/DDV
By using classwizard to add member variables to the dialog class, you can use the efficient features provided by classwizard to automatically generate source code for dialog data exchange and dialog data verification, that is, the well-known DDX/DDV.
Data exchange and verification are only applied to the member variables for which the value category is selected. That is, cstring, bool, number, coledatetime or colecurrency.
Dialog Box data exchange is responsible for data entry and exit in the control. When a dialog appears for the first time, each control window is automatically initialized with the value of the corresponding member variable. When you click the OK button or press enter to close the dialog, the control will be copied back to the variable no matter which value or text it contains.
Dialog Data Verification ensures that the value falls within the specified limits. The exchange and verification mechanisms are provided by the MFC framework. Each function has a prefix DDX _ or DDV _ to identify it as a data exchange or data verification function.
1. dialog data exchange (DDX)
Common conversation data exchange functions
(1) Exchange Function: ddx_cbindex, which obtains/sets the Data Type: int, which is applied to the control: ComboBox
(2) Exchange Function: ddx_cbstring. The data type of the obtained/set: cstring, which is applied to the control: ComboBox.
(3) exchange function: ddx_cbstringexact. The data type of the obtained/set: cstring, which is applied to the control: ComboBox.
(4) exchange function: ddx_check. The data type obtained/set: intcheck, which is applied to the control: box.
(5) exchange function: ddx_datetimectrl. The data type of the obtained/set: ctime, which is applied to the control: datetimepicker.
(6) exchange function: ddx_lbindex, which obtains/sets the Data Type: int, which is applied to the control: list box.
(7) exchange function: ddx_lbstring. The data type of the obtained/set: cstring, which is applied to the control: ListBox.
(8) exchange function: ddx_lbstringexact. The data type of the obtained/set: cstring, which is applied to the control: list box.
(9) exchange function: ddx_monthcalctrl, to obtain/set the Data Type: ctime, applied to the control: month calendar
(10) exchange function: ddx_radio, which obtains/sets the Data Type: int, which is applied to the control: radio button.
(11) exchange function: ddx_scroll. The data type obtained/set: int, which is applied to the control: scroll bar.
(12) exchange function: ddx_text. The data type obtained/set: cstring or numerical (byte, short, Int, uint, long, etc.) is used in the control: Edit Control.
Among all data exchange functions, this function is unique and only applies to a group of controls, not a control. Ddx_radio returns an int value to indicate which button in the group is opened: 0 indicates the first button in the group, 1 indicates the second button, and so on. Value-1 indicates that all buttons in the group are cleared. You can call ddx_radio to determine the status of a single radio button (if it is the only button in the group ). In this case, the return value 0 indicates that the button is open, and the value-1 indicates that the button is closed.
Creating a single-choice button is usually done in the dialog editor, and we will see it later.
MFC provides a large number of dialog data exchange functions that can move data between control member variables in the dialog class. In addition to the common functions listed, there are also special exchange functions used to record set data and data returned by ActiveX controls. The ddx_control function can transmit data for several different types of controls, such as animate and IPaddress.
2. dialog data verification (DDV) dialog data verification functions, which are only used to accept control member variables used to input data from the keyboard. In other words, it is to edit controls and combos.
Dialog data verification function
(1) ddv_minmaxbyte specifies a byte value within the limit range.
(2) ddv_minmaxint specifies an int value within the limit range.
(3) ddv_minmaxuint specifies a unit value within the limit range.
(4) ddv_minmaxlong specifies a long value within the limit range.
(5) ddv_minmaxdword specifies a DWORD value within the restricted range.
(6) ddv_minmaxfloat specifies a float value within the limit range.
(7) ddv_minmaxdouble specifies a double value within the limit range.
(8) The length of the ddv_maxcharscstring string cannot exceed the specified maximum length.
When you add a member variable to the edit control or combo box and select a control in the control IDs box on the member variable tab, one of the two prompts will appear at the bottom of the tab. Which prompt depends on whether the variable has numeric data or text data. In either case, enter the variable limit value for verification.
In addition to a conversation data verification function, all functions monitor numeric data to ensure that user-input values fall between the specified upper and lower limits.
The exception is the ddv_maxchars function, which is used to verify that the number of characters entered into the edit control or combo cannot exceed the given maximum value. Unlike an exchange function, a function is used only when the conversation is closed, but not when it appears.
If the value of the input control falls beyond the specified limit, the verification function of the control displays a message box to notify the user of a problem. When the message box is closed, the problematic control has a focus, prompting the user to re-enter the data. Unless all data verification functions are satisfied, you cannot Click OK to close the dialog.
DDX and DDV -- Transfer of values between controls and variables