Adding a Member Variable (Visual C++)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Adding a Member Variable (Visual C++).

You can 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 specifically designed to take the relevant information and use it to insert elements in your source files at the appropriate locations. You can add a member variable from the Dialog editor in Resource View, or from Class View.

System_CAPS_ICON_note.jpg Note

When you are 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, click Add Variable to display the Add Member Variable Wizard.

    System_CAPS_ICON_note.jpg Note

    A default value is already provided in Control ID.

  5. Provide the information in the appropriate wizard boxes. See Dialog Box Controls and Variable Types for more information.

  6. Click 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, click Add, and then click Add Variable to display the Add Member Variable Wizard.

  4. Provide the information in the appropriate wizard boxes. See Add Member Variable Wizard for details.

  5. Click Finish to add the definition and implementation code to the project and close the wizard.

Adding Functionality with Code Wizards
Adding a Class
Adding a Member Function
MFC Message Handler
Navigating the Class Structure

Show: