Defining Member Variables for DDX

OverviewHow Do I

You can use ClassWizard to define member variables for dialog box controls.

To define data members for dialog data exchange

  1. Create your dialog box, place in it the controls you want, and set the appropriate control styles in the Properties window. Then use ClassWizard to define a new dialog box class. For more information, see Adding a Class.

  2. On the View menu, click ClassWizard. In ClassWizard, click the Member Variables tab.

    Note   For a recordset class, Update Columns updates the current static list with the current database list. Members assigned to a deleted column may be deleted.

    The Bind All command creates an initial recordset with a default member name for every column in the table.

  3. In the Control IDs box, select the control for which you want to set up dialog data exchange (DDX), and click Add Variable.

    The Add Member Variable dialog box appears.

  4. In the Member Variable Name box, type the name of the new variable. ClassWizard provides the m_ prefix to identify it as a member variable.

  5. In the Category box, select whether this variable is a Value variable or a Control variable.

    For standard Windows controls, click Value to create a variable that contains the control's text or status as typed by the user. The framework automatically converts the control's data to the data type selected in the Variable Type box (see the table in What Are the Variable Types for the DDX Control Property?).

    You can also choose Control in the Category drop-down list to create a Control variable that gives you access to the control itself (see the table in What Are the Variable Types for the DDX Control Property?).

  6. In the Variable type box, choose from a list of variable types appropriate to the control (see the tables in What Are the Variable Types for the DDX Value Property? and in What Are the Variable Types for the DDX Control Property?).

  7. Click OK.

    The new member variable is added to the Control IDs list.

Once you have defined a DDX Value variable for a standard Windows control, the framework automatically initializes and updates the variable for you.

You can now use ClassWizard to bind a member variable to the value of a scroll-bar control, using the Value property and the int data type, as well as to a CScrollBar object, using the Control property. The Value property binds the value of a scroll-bar control (the position of the scroll box, or "thumb"). ClassWizard enables DDX for a scroll bar by calling DDX_Scroll in your DoDataExchange override.

If your DoDataExchange function contains a call to DDX_Scroll, you must additionally set the scroll-bar range before that call, as shown in the following code:

void CMyDlg::DoDataExchange( CDataExchange* pDX )
{
    CScrollBar* pScrollBar = (CScrollBar*)GetDlgItem( IDC_SCROLLBAR1 );
    pScrollBar->SetScrollRange( 0, 100 );
    CDialog::DoDataExchange( pDX );
    //{{AFX_DATA_MAP(CMyDlg)
    DDX_Scroll(pDX, IDC_SCROLLBAR1, m_nScroll );
    //}}AFX_DATA_MAP
}