Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Creating An ActiveX Control using VC++.NET

0.00/5 (No votes)
5 Jul 2004 1  
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