description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CDataExchange Class |
CDataExchange Class |
11/04/2016 |
|
|
84ed6113-325d-493e-a75d-223f03a992b8 |
Supports the dialog data exchange (DDX) and dialog data validation (DDV) routines used by the Microsoft Foundation classes.
class CDataExchange
Name | Description |
---|---|
CDataExchange::CDataExchange | Constructs a CDataExchange object. |
Name | Description |
---|---|
CDataExchange::Fail | Called when validation fails. Resets focus to the previous control and throws an exception. |
CDataExchange::PrepareCtrl | Prepares the specified control for data exchange or validation. Use for nonedit controls. |
CDataExchange::PrepareEditCtrl | Prepares the specified edit control for data exchange or validation. |
CDataExchange::PrepareOleCtrl | Prepares the specified OLE control for data exchange or validation. Use for nonedit controls. |
Name | Description |
---|---|
CDataExchange::m_bSaveAndValidate | Flag for the direction of DDX and DDV. |
CDataExchange::m_pDlgWnd | The dialog box or window where the data exchange takes place. |
CDataExchange
does not have a base class.
Use this class if you are writing data exchange routines for custom data types or controls, or if you are writing your own data validation routines. For more information on writing your own DDX and DDV routines, see Technical Note 26. For an overview of DDX and DDV, see Dialog Data Exchange and Validation and Dialog Boxes.
A CDataExchange
object provides the context information needed for DDX and DDV to take place. The flag m_bSaveAndValidate is FALSE when DDX is used to fill the initial values of dialog controls from data members. The flag m_bSaveAndValidate is TRUE when DDX is used to set the current values of dialog controls into data members and when DDV is used to validate the data values. If the DDV validation fails, the DDV procedure will display a message box explaining the input error. The DDV procedure will then call Fail
to reset the focus to the offending control and throw an exception to stop the validation process.
CDataExchange
Header: afxwin.h
Call this member function to construct a CDataExchange
object.
CDataExchange(
CWnd* pDlgWnd,
BOOL bSaveAndValidate);
pDlgWnd
A pointer to the parent window that contains the control. Usually this is a CDialog-derived object.
bSaveAndValidate
If TRUE, this object validates data, then writes data from the controls to the members. If FALSE, this object will move data from members to controls.
Construct a CDataExchange
object yourself to store extra information in the data exchange object to pass to your window's CWnd::DoDataExchange member function.
[!code-cppNVC_MFCControlLadenDialog#70]
The framework calls this member function when a dialog data validation (DDV) operation fails.
void Fail();
Fail
restores the focus and selection to the control whose validation failed (if there is a control to restore). Fail
then throws an exception of type CUserException to stop the validation process. The exception causes a message box explaining the error to be displayed. After DDV validation fails, the user can reenter data in the offending control.
Implementors of custom DDV routines can call Fail
from their routines when a validation fails.
For more information on writing your own DDX and DDV routines, see Technical Note 26. For an overview of DDX and DDV, see Dialog Data Exchange and Validation and Dialog Box Topics.
This flag indicates the direction of a dialog data exchange (DDX) operation.
BOOL m_bSaveAndValidate;
The flag is nonzero if the CDataExchange
object is being used to move data from the dialog controls to dialog-class data members after the user edits the controls. The flag is zero if the object is being used to initialize dialog controls from dialog-class data members.
The flag is also nonzero during dialog data validation (DDV).
For more information on writing your own DDX and DDV routines, see Technical Note 26. For an overview of DDX and DDV, see Dialog Data Exchange and Validation and Dialog Box Topics.
Contains a pointer to the CWnd object for which dialog data exchange (DDX) or validation (DDV) is taking place.
CWnd* m_pDlgWnd;
This object is usually a CDialog object. Implementors of custom DDX or DDV routines can use this pointer to obtain access to the dialog window that contains the controls they are operating on.
For more information on writing your own DDX and DDV routines, see Technical Note 26. For an overview of DDX and DDV, see Dialog Data Exchange and Validation and Dialog Box Topics.
The framework calls this member function to prepare the specified control for dialog data exchange (DDX) and validation (DDV).
HWND PrepareCtrl(int nIDC);
nIDC
The ID of the control to be prepared for DDX or DDV.
The HWND of the control being prepared for DDX or DDV.
Use PrepareEditCtrl instead for edit controls; use this member function for all other controls.
Preparation consists of storing the control's HWND in the CDataExchange
class. The framework uses this handle to restore the focus to the previously focused control in the event of a DDX or DDV failure.
Implementors of custom DDX or DDV routines should call PrepareCtrl
for all non-edit controls for which they are exchanging data via DDX or validating data via DDV.
For more information on writing your own DDX and DDV routines, see Technical Note 26. For an overview of DDX and DDV, see Dialog Data Exchange and Validation and Dialog Box Topics.
The framework calls this member function to prepare the specified edit control for dialog data exchange (DDX) and validation (DDV).
HWND PrepareEditCtrl(int nIDC);
nIDC
The ID of the edit control to be prepared for DDX or DDV.
The HWND of the edit control being prepared for DDX or DDV.
Use PrepareCtrl instead for all non-edit controls.
Preparation consists of two things. First, PrepareEditCtrl
stores the control's HWND in the CDataExchange
class. The framework uses this handle to restore the focus to the previously focused control in the event of a DDX or DDV failure. Second, PrepareEditCtrl
sets a flag in the CDataExchange
class to indicate that the control whose data is being exchanged or validated is an edit control.
Implementors of custom DDX or DDV routines should call PrepareEditCtrl
for all edit controls for which they are exchanging data via DDX or validating data via DDV.
For more information on writing your own DDX and DDV routines, see Technical Note 26. For an overview of DDX and DDV, see Dialog Data Exchange and Validation and Dialog Box Topics.
The framework calls this member function to prepare the specified OLE control for dialog data exchange (DDX) and validation (DDV).
COleControlSite* PrepareOleCtrl(int nIDC);
nIDC
The ID of the OLE control to be prepared for DDX or DDV.
A pointer to the OLE control site.
Use PrepareEditCtrl instead for edit controls or PrepareCtrl for all other non-OLE controls.
Implementors of custom DDX or DDV routines should call PrepareOleCtrl
for all OLE controls for which they are exchanging data via DDX or validating data via DDV.
For more information on writing your own DDX and DDV routines, see Technical Note 26. For an overview of DDX and DDV, see Dialog Data Exchange and Validation and Dialog Box Topics.
MFC Sample VIEWEX
Hierarchy Chart
CWnd::DoDataExchange
CWnd::UpdateData