Add a member variable (original) (raw)

You may add a member variable to a class using Class View. Member variables can be either for data exchange and data validation, or they can be generic. The data member variable wizard is designed to take the relevant information and use it to insert elements in your source files at the appropriate locations. You may add a member variable from the Dialog editor in Resource View, or from Class View.

Note

When you're designing and implementing a dialog box, you might find it more efficient to use the Dialog editor to add the dialog box controls, and then to implement the controls' member variables.

To add a member variable for a dialog control in Resource View using the Add Member Variable Wizard:

  1. In Resource View, expand the project node and the Dialog node to display the list of the project's dialog boxes.
  2. Double-click the dialog box to which you want to add the member variable to open it in the Dialog editor.
  3. In the dialog box displayed in the Dialog editor, right-click the control to which you want to add the member variable.
  4. On the shortcut menu, choose Add Variable to display the Add member variable wizard.
    Note
    A default value is already provided in Control ID.
  5. Provide the information in the appropriate wizard boxes. For more information, see dialog box controls and variable types.
  6. Select Finish to add the definition and implementation code to the project and close the wizard.

To add a member variable from Class View using the Add Member Variable Wizard:

  1. In Class View, expand the project node to display the classes in the project.
  2. Right-click the class to which you want to add a variable.
  3. On the shortcut menu, choose Add, and then choose Add Variable to display the Add Member Variable Wizard.
  4. Provide the information in the appropriate wizard boxes. For more information, see Add member variable wizard.
  5. Select Finish to add the definition and implementation code to the project and close the wizard.

In this section

Add member variable wizard

This wizard adds a member variable declaration to the header file. Depending on the options, it can add code to the .cpp file. Once you've added the member variable using the wizard, you can edit the code in the development environment.

Dialog box controls and variable types

You can use the add member variable wizard to add a member variable to a dialog box control created using MFC. The type of control for which you add the member variable determines the options that appear in the dialog box.

The following table describes all the dialog box control types that are supported in MFC and the Dialog editor. It also displays their available types and values.

Control Control type Control variable type Value variable type Min/max values (value type only)
Animation control SysAnimate32 CAnimateCtrl None; control only N/A
Button BUTTON CButton None; control only N/A
Check box CHECK CButton BOOL Min value/Max value
Combo box COMBOBOX CComboBox CString Max characters
Date time picker control SysDateTimePick32 CDateTimeCtrl CTime Min value/max value
Edit box EDIT CEdit CString, int, UINT, long, DWORD, float, double, BYTE, short, BOOL, COleDateTime, or COleCurrency Min value/max value; some support max characters
Hotkey control msctls_hotkey32 CHotKeyCtrl None; control only N/A
List box LISTBOX CListBox CString Max characters
List control SysListView32 CListCtrl None; control only N/A
Month Calendar control SysMonthCal32 CMonthCalCtrl CTime Min value/max value
Progress control msctls_progress32 CProgressCtrl None; control only N/A
Rich Edit 2 control RichEdit20A CRichEditCtrl CString Max characters
Rich Edit control RICHEDIT CRichEditCtrl CString Max characters
Scroll bar (vertical or horizontal SCROLLBAR CScrollBar int Min value/max value
Slider control msctls_trackbar32 CSliderCtrl int Min value/max value
Spin control msctls_updown32 CSpinButtonCtrl None; control only N/A
Tab control SysTabControl32 CTabCtrl None; control only N/A
Tree control SysTreeView32 CTreeCtrl None; control only N/A