Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 15: Fundamental Controls


void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, double& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, COleCurrency& value );
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, COleDateTime& value );

The first argument, pDX, is a pointer to CDataExchange. The second argument, nIDC, is
the identifier the of the control you want to refer to. The third argument, value, if the
name of the value variable you had previously declared.

If a control holds a valid value, you can declare both a control variable and a value
variable if you need them. Here is an example:

class CExchangeDlg : public CDialog
{

...
public:
CStatic stcAdvanced;
CString valAdvanced;
CString strFullName;
};


When mapping such variable, make a call to DDX_Control() for the control variable and
a separate call to DDX_X() for the value variable. Because there are various types of
DDX_ functions for the controls, X stands for the type of control referred to.

Like the DDX_Control(), the DDX_X() function can be called for each variable you
intend to map to a control and this is performed in the CWnd::DoDataExchange()
event. This CDataExchange pointer is passed as the first argument to the DDX_ X()
functions. This argument allows the dialog box to update the values held by the controls.

Once again, avoid declaring and mapping value variables manually. Instead, use either
(MSVC 6) the ClassWizard or (MSVC 7) the Add Member Variable Wizard to add a
variable that you want to associate with a control on a dialog-based object.

Practical Learning: Adding Value Variables



  1. From the Resource View tab, open the IDD_CIRCULAR dialog box and adjust the
    locations and dimensions of the controls as you see fit

  2. To declare a value variable, on the dialog box, right-click the edit box on the right
    side of the top Radius and click Add Variable...

Free download pdf