Click here to Skip to main content
15,887,683 members
Articles / Programming Languages / C++
Article

Creating An ActiveX Control using VC++.NET

Rate me:
Please Sign up or sign in to vote.
2.44/5 (37 votes)
5 Jul 20042 min read 133.9K   1.5K   26   25
An understanding of ActiveX controls.

Sample Image - picture1.jpg

A view of ActiveX Control Test Container.

Sample screenshot

A view of an ActiveX control used in a Visual Basic .NET application.

Introduction

An ActiveX control is a software component that can be plugged into many different programs and used as if it were a native part of the program. It's similar to the concept of a separate head phone. If you have a computer, just plug into it, it works with your computer. ActiveX controls bring the same type of interoperability to software applications.

Required things

  • Visual Studio .NET
  • Windows 2000/XP

Working

Create MFC ActiveX control wizards application, named as MyActiveXIcon, In the class named CMyActiveXIconCtrl, use the OnDraw function. This function is called by the framework to draw the control in the specified bounding rectangle using the specified device context.

void CMyActiveXIconCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)

This function is to draw the ActiveX control icon.

CBitmap::LoadBitmap()

This function loads the MyActiveXIcon bitmap file using the resource ID, IDB_MyActiveXIcon. Then bitmap file is used by the memDC, which is the compatible device context (DC) with the current DC.

CDC::StretchBlt()

This function resizes the MyActiveXIcon by stretching the AcitveXControl icon to fit the current size of the Device Context. Now, run the program. In Visual C++ .NET, it automatically registers the control.

Then go to the Tools menu and click on ActiveX Control Test container. It displays the window, in which, go to the Edit menu and click on Insert Control option. A window will appear, check the MyActiveX Icon Control, you see this like in the above picture which shows the ActiveX Control Test Container.

How to use in an application

For this moment, I tell you how to use it in VB.NET. Create a Windows application. Go to the toolbox window, right click on it, and click on the Customize toolbox. A dialog appears with two tab controls. Use the COM tab and check the My ActieXControl icon. Now, it will appear on the toolbox. Click it and add it on your form.

If you have any suggestions, send me an email, I will be thankful to you.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Pakistan Pakistan
I did Msc Computer Scicences specialization in software engineering from University of Management and Technology Lahore,and having the experience of IT for more than 5 years.
I have worked in different programming languages, such as: C, C++, Visual C++,Java, Visual Basic and C#, also in PHP, HTML, ASP, ASP.NET and also CCNA & RedHat Linux. Love Mathematics. I have always been fascinated by .NET, so now I am programming in .NET.

You can email me: only_boby@hotmail.com
Visit my web site: http://www28.brinkster.com/abdulhye

Comments and Discussions

 
GeneralKnoweldge about ActiveX Pin
g1d111-Dec-07 0:32
g1d111-Dec-07 0:32 
Generalthat is not c++.NET! Pin
zanadar10-Dec-07 18:04
zanadar10-Dec-07 18:04 
GeneralVC++.net 2003 Pin
minad_78610-Sep-07 3:25
minad_78610-Sep-07 3:25 
GeneralVS2005 crashes after the active-x control was added Pin
Andy Jey7-Nov-06 16:32
Andy Jey7-Nov-06 16:32 
GeneralSomething to watch out for... Pin
Paul Vickery6-Nov-06 6:31
professionalPaul Vickery6-Nov-06 6:31 
I recently created a basic ActiveX control as a starting point for a project I'm converting to an ActiveX control. I used AppWizard in VS 2005, and called my project "TestCtrl". I then, in the dialog allowing the class name etc to be modified, I noticed that by default "Ctrl" was appended to the name. As I didn't want it called "TestCtrlCtrl", I remove the final "Ctrl". After finishing the Wizard, I built the project, and it wouldn't build. It complain about several things not being defined, including _tlid.

I tried exactly the same in VC6, and it worked fine, so I compared all the files that were generated.

I found that VS.NET will generate some file names as <project>.cpp/h and others as <project>Ctrl.cpp/h. So, mine would have been TestCtrl.cpp/h and TestCtrlCtrl.cpp/h. By removing the Ctrl appended to my project name, the files had become TestCtrl.cpp/h and, oh, another TestCtrl.cpp/h. So, the first set generated, which defined _tlid etc, was overwritten by the second set with the same names! VC6 used a slightly different naming convention, and so this problem didn't arise.

So, anyway, it's all sorted, and I'm not going mad (which was my first thought) and there's not some fundamental bug in the AppWizard which prevents ActiveX controls being created (my second thought). Something to bear in mind though for future projects...




"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)

GeneralVery Big Problem Pin
Ahmed Charfeddine10-Jul-06 2:20
Ahmed Charfeddine10-Jul-06 2:20 
Generalgood article Pin
ttt_say8-Feb-06 18:26
ttt_say8-Feb-06 18:26 
QuestionCan I make ActiveX by C#? Pin
thainam6-Oct-05 20:04
thainam6-Oct-05 20:04 
Generalgood job Pin
TuPacMansur12-Sep-05 17:42
TuPacMansur12-Sep-05 17:42 
QuestionCan you put your ActiveX to device control? Pin
hwang82222-Aug-05 10:41
hwang82222-Aug-05 10:41 
AnswerRe: Can you put your ActiveX to device control? Pin
Abdul Hye23-Aug-05 19:59
Abdul Hye23-Aug-05 19:59 
GeneralRe: Can you put your ActiveX to device control? Pin
hwang2k24-Aug-05 3:03
hwang2k24-Aug-05 3:03 
QuestionActiveX on .Net ? Pin
Anonymous29-Apr-05 3:22
Anonymous29-Apr-05 3:22 
AnswerRe: ActiveX on .Net ? Pin
Abdul Hye30-Apr-05 21:08
Abdul Hye30-Apr-05 21:08 
QuestionAnd where is the wizard to delete methods. properties and events? Pin
Roger Bamforth26-Apr-05 5:58
Roger Bamforth26-Apr-05 5:58 
QuestionWhere is the wizard to add properties and methods? Pin
SohailB26-Mar-05 20:51
SohailB26-Mar-05 20:51 
AnswerRe: Where is the wizard to add properties and methods? Pin
MMansonFan2529-Mar-05 17:08
MMansonFan2529-Mar-05 17:08 
GeneralRe: Where is the wizard to add properties and methods? Pin
Abdul Hye30-Mar-05 6:19
Abdul Hye30-Mar-05 6:19 
GeneralCreating ActiveX from C# Pin
drubio15-Nov-04 21:36
drubio15-Nov-04 21:36 
GeneralRe: Creating ActiveX from C# Pin
Abdul Hye28-Nov-04 6:20
Abdul Hye28-Nov-04 6:20 
GeneralRe: Creating ActiveX from C# Pin
JavierJJJ20-Nov-05 21:47
JavierJJJ20-Nov-05 21:47 
GeneralNice article Pin
kaka_0026-Jul-04 4:10
kaka_0026-Jul-04 4:10 
GeneralRe: Nice article Pin
Abdul Hye6-Jul-04 18:57
Abdul Hye6-Jul-04 18:57 
QuestionCan i used it in VC.Net? Pin
coco_556-Jul-04 2:18
coco_556-Jul-04 2:18 
AnswerRe: Can i used it in VC.Net? Pin
Abdul Hye6-Jul-04 18:59
Abdul Hye6-Jul-04 18:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.