Browse » Home
Tuesday, February 21, 2012
How to Build ActiveX Controls
Visual Basic 6.0
1. Start Visual Basic. Click on 'File' and then 'New Project.' Select 'ActiveX Control' from the list of projects and click 'OK.' Click on the 'Name' property for the control and enter a new name, for example 'TestControl.'
2. Double-click on objects in the toolbox to add them to the control. Click and drag these controls on the form to arrange their appearance.
3. Double-click on one of the controls on the form to open up the code window. Type the code that will determine how the control responds to user events.
4. Press 'F5' to test the control. Press' OK' to start the control in an web browser. Test the objects when the control loads. Stop running the program and fix any errors.
5. Click on 'File' and select 'Make TestControl.ocx' to create the ActiveX control.
Visual C++ 6.0
6. Start Visual C++. Click on 'File' and then 'New.' Select 'MFC ActiveX ControlWizard' from the list.
7. Type a name in the project name text box, for example 'TestControl.' Click 'OK' to open the project wizard. Click 'Finish' to create the project files.
8. Right-click on '_DTestControlEvents' and select 'Add Event.' Click on the external name drop-down list and select an event. Click on the 'Custom' radio button and enter parameters in the list if you need them. Click 'OK' to create this event.
9. Click on '_DTestControl' and select 'Add Method.' Select external and internal names and a return type. Add parameters to the parameter list if needed and click 'OK.' Enter the class header file and define the method.
10. Open the 'TestControlCtl.cpp' file's code window. Define your method by coding it.
11. Create other events and methods similarly. Open the declaration file and declare your message and error handlers like you would in any other C++ project. Open the cpp file and define these handlers.
12. Press the 'Run' button or 'CTRL+F5' to test the control. In the executable file name box, click on the arrow and select 'ActiveX Control Test Container' and click 'OK.'
13. Click on 'Edit,' then 'Insert New Control.' Locate your ActiveX Control in the list, click on it and then click 'OK.' Click on 'Control' and then 'Invoke Methods' to test the methods you created. Close the test window and fix any errors.
14. Save the project files. Click on 'Build' and then 'Build TestControl.ocx' or press 'F7' to create the ActiveX control.