This article is for those enthusiastic VC++ developers who want to build their own ActiveX controls but
don\u2019t know where to start with. This article will take you to build your first ActiveX control. This article will
show you the step by step method to build a control which draws different waveforms (Sin/Cos).I assume
that you are familiar with VC++ and know some basics of ActiveX control.
combo box with the prompt Which window class, if any, should this control subclass?.
Drop down the list and select the entrySTATIC from that list. We're using a static
control in this example since we'll just be displaying data (and not accepting input).
CPlotApp - The ActiveX "appliction" class is derived from COleControlModule. The COleControlModule class is the base class from which you derive an OLE control module object. This class provides member functions for your control module's initialization (InitInstance) and cleanup code (ExitInstance).
CPlotCtrl - The second class is derived from COleControl and will provide most
of the functionality to your control. This is the class where you will write the
majority of the your code.
CPlotPropPage - The third class is CPlotPropPage, (derived from
COlePropertyPage). This class is used to manage the property page dialog of
your control. In addition to this class, a dialog resource is also created that will
serve as the property page for the control.
The term stock properties means that its one of a set of common properties that MFC code stores
and initializes for you. The MFC code also performs appropriate action when the value of a stock
property is changed. The ClassWizard provides code for changing nine (9) such properties. Since
these properties are built-in, they are obviously the easiest to deal with in terms of the work
required by the developer. As you'll see shortly, you literally don't add a single line of code to add
stock property to your control!
From these, we will work with the Appearance, BackColor, ForeColor and BorderStyle properties.
We'll start by adding theBackCol or stock property
ClassWizard will store the value of the BackColor property and initialize it to background
color of the container window. The ClassWizard will also add the following line to your
control's ODL file:
Finally, ClassWizard will also add the code to invalidate the control whenever the value of
the BackColor property changes, thereby forcing the OnDraw function to redraw the
control. The only thing you have to do is to use the color contained in the property to
paint the background color of control.
Now insert the following line just before the END_PROPPAGEIDS line (The
CLSID_CColorPropPage is defined automatically since this is a property page CLSID for a
This action might not be possible to undo. Are you sure you want to continue?