Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1


Ratings: (0)|Views: 36|Likes:
Published by api-3767556

More info:

Published by: api-3767556 on Oct 16, 2008
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less






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.

Creating an ActiveX Control
Simply follow these steps in order to create an ActiveX control.
1. Using the AppWizard to create an ActiveX Control project
1.SelectNew fromFile menu
2.Click theProjec ts tab and select the type of project as MFC ActiveX Control Wizard
from the list.
3.Name of new projectPlot and then click theOK button.
4.Take all the defaults values of the next dialog (titled MFC ActiveX Control Wizard -
Step 1 of 2) and click theNext button
5.From the next dialog (titled MFC ActiveX Control Wizard - Step 2 of 2), locate the

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).

6.Click onAdvanced button and check the Flicker free activation checkbox.
7.Now click theFinish button. At this point, the AppWizard will generate the following
three classes on your behalf:

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.

2.Adding "Stock" properties

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!

The ClassWizard provides code for the following stock properties:

From these, we will work with the Appearance, BackColor, ForeColor and BorderStyle properties.
We'll start by adding theBackCol or stock property

1.From the ClassWizard, click theAutomat ion tab.
2.Ensure that the CPlotCtrl class is selected in the Class name combobox. Now, Click the
Add Property button to display the Add Property dialog.
3.Once the Add Property dialog does appear, select theBackColor property from the
External Name combo box. (It is called the "external name" because this is how users of
the control will refer to it.)
4.Verify that theStock radio button is selected in theImplementation groupbox.
5.Click theOK button to finish the generation of the stock property. At this point, the

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:

6. [id(DISPID_BACKCOLOR), bindable, requestedit] OLE_COLOR

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.

7. At this point, add the following two (2) lines of code to the end of the CPlotCtrl::OnDraw
member function
8. CBrush bkBrush(TranslateColor(GetBackColor()));
9. pdc->FillRect(rcBounds,&bkBrush);
10.Now, let's add a Color property page to the program. This page will allow users of the
control to change the BackColor our newly added property property at design-time. To
do this, simply open thePlotCtr l.cpp file and locate the // Property pages comment.
Once you've done that, you should see the following:
The first line tells the compiler how many pages exist. Notice that it's set to 1. Change
this value to 2 as we're going to add a new page.

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
stock property).

Once you've finished, your new property page id map should look like the following:


Once you make the above changes,the stock property page is automatically linked to the
BackColor property.
11.Now that you've seen how to add the BackColor stock property to an ActiveX control,
follow these same steps in order to add theAppearance,ForeCol or andBorderStyle
properties. Note that you do not need to add a property page for the other
12.After adding these stock properties, build your control and test it using ActiveX Test
Container (which is usually found under the Tools menu. As you can see in the figure
below, the ClassWizard has added the appropriate controls for changing the stock

Activity (5)

You've already reviewed this. Edit your review.
1 hundred reads
manjunathp079030 liked this
abhijanu liked this
jfscrbd liked this
kr0465 liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->