Adding a Control to a Project in C++ (Using Visual .Net)

This walkthrough explains how to use an ActiveX Control in your own project. Before you begin you need to have the ActiveX Control you intend to use registered on your computer. For this walkthrough I will be using the Mp3P control (mp3p.ocx).

Step 1 - Add ActiveX Control

Within your project there should be a way to insert an ActiveX Control. In Visual Studio C++ I do this by right-clicking on my program dialog and selecting "Insert ActiveX Control."


This will display a dialog for you to select from all of the registered controls on your computer. After selecting the "Mp3P Control" it is added to my project and looks like a little white box.

Step 2 - Add Member Variable

Now that the control has been added to your project, you can add a member variable to represent the control. I did this by right-clicking the control and selecting "Add Variable" (this may be different for you). The variable is an ocx control type variable.

Once the variable has been added, you can use it to invoke methods or access properties of the control. For example, my variable is called "m_mp3control". To call the "Play" method of the Mp3P control within my program, I add the line

m_mp3control.Play();

Step 3 - Add Event Handler

In addition to accessing methods and properties, you can handle events that are fired by a control. Adding an event handler should be similar to adding a variable. I did this by right-clicking the control and selecting "Add Event Handler. This popped up a window that allowed me to pick from the list of events for this control.


After the event handler has been added, you should have a method in which you can add code for whenever this event is fired by the control.

 

Moon Valley Software