Share via


ActiveX Controls: Adding Stock Methods to an ActiveX Control

OverviewHow Do IFAQSample

A stock method differs from a custom method in that it is already implemented by class . For example, COleControl contains a predefined member function supports the Refresh method for your control. The dispatch map entry for this stock method is DISP_STOCKFUNC_REFRESH.

COleControl supports two stock methods: DoClick and Refresh. Refresh  is invoked by the control’s user to immediately update the control’s appearance; DoClick is invoked to fire the control’s Click event.

Method Dispatch Map Entry Comment
DoClick DISP_STOCKPROP_DOCLICK( ) Fires a Click event.
Refresh DISP_STOCKPROP_REFRESH( ) Immediately updates the control’s appearance.

Adding a Stock Method Using ClassWizard

Adding a stock method is simple using ClassWizard. The following procedure demonstrates adding the Refresh method to a control created using ControlWizard.

To add the stock Refresh method using ClassWizard

  1. Load your control’s project.

  2. On the View menu, click ClassWizard.

  3. Choose the Automation tab.

  4. Click the control class in the Class name box.

  5. Click Add Method.

  6. In the External name box, click Refresh.

  7. Click OK.

  8. Click OK to confirm your choices and close ClassWizard.

The following figure shows the Add Method dialog box of ClassWizard.

The Add Method Dialog Box

ClassWizard Changes for Stock Methods

Because the stock Refresh method is supported by the control’s base class, ClassWizard does not change the control’s class declaration in any way. It simply adds an entry for the method to the control’s dispatch map and to its .ODL file. The following line is added to the control’s dispatch map, located in its implementation (.CPP) file:

DISP_STOCKFUNC_REFRESH( )

This makes the Refresh method available to the control’s users.

The following line is added to the control’s .ODL file:

[id(DISPID_REFRESH)] void Refresh();

This line assigns the Refresh method a specific ID number.