次の方法で共有


Declaring a Variable Based on Your New Control Class

OverviewHow Do I

Once you have created an MFC control class, you can use ClassWizard to declare a variable based on it. To provide a context that ClassWizard can use to place the new variable, you must open the dialog editor and edit the dialog box in which you want to use your reusable control. Moreover, the dialog box must already have a class associated with it. For information on using the dialog editor, see Dialog Editor Topics for Visual C++. For information on using ClassWizard to add a class, see Adding a Class.

To declare a variable based on your reusable class

  1. While editing the dialog box, drag a control of the same type as the base class of your new control from the Controls toolbar onto the dialog box.

  2. Place the mouse pointer over the dropped control.

  3. While holding down the CTRL key, double-click the control.

    The Add Member Variable dialog box appears.

  4. In the Member Variables Name text box, type a name.

  5. In the Category drop-down list, click Control.

  6. From the Variable type drop-down list, select the name of your reusable control.

  7. Click OK.

    A message box reminds you to include (#include) your reusable control's header (.h) file into the project so that the compiler has access to its symbols. ClassWizard has no safe way of guaranteeing that your control class is in the scope of the dialog class.

  8. Click OK, and remember to include your control's .h file.

    ClassWizard generates dialog data exchange (DDX) code to attach your control class to the dialog control. Note that this procedure automatically subclasses the dialog control.