Views Foundation > Creating an ActiveX Control from Existing Rogue Wave Views Code > Creating an ActiveX Control with the ATL Library > Step 1: Preparing the Program
 
Step 1: Preparing the Program
This step prepares the sample application used as a starting point for this tutorial so that it can be transformed to an ActiveX control and used inside another application. Basically what you have to do is separate the data from the code and make it possible to create the main view either as a top view (which is the case in the original program) or as a child view which can become part of a parent window.
Also these modifications will make it easier for you to add new functionality to the ActiveX control. The modified files are in the step1 directory.
You are going to:
*Separate data from the code and put it into an .ilv file.
*Encapsulate the initialization code in a Ctrl class.
*Create a resource file (.rc) with ilv2data.
*Modify the manager.cpp file.
Separate data from the code and put it into an .ilv file.
Data stored in .ilv files is easier to modify than data stored as a string in a .cpp file. Also, any dependency problems can be solved with the Rogue Wave Views data files packaging tool, ilv2data.
The result is in the file step1\data\ctrl.ilv.
Notice that we have added attachments so that the main view can be resized in a consistent way. Also, we have named objects so that they can be accessed more easily from the program. All of these enhancements were made with Rogue Wave Views Studio.
Note: The separation of data from the code is not really necessary in this tutorial. However it is recommended to facilitate modifications.
Encapsulate the initialization code in a Ctrl class.
The initialization code is encapsulated in the Ctrl class that will be used to create the ActiveX control and interact with it.
This class is declared in the file step1\ctrl.h and is defined in the file step1\ctrl.cpp. This cpp file also stores the callback functions.
The Ctrl class is basic. It derives from IlvGadgetContainer. It is composed of only three constructors and four member functions, of which one is private:
*The first constructor creates the Ctrl object as a top view, as in the original version of the file. It is used in the main function in step1\manager.cpp and has the following signature:
Ctrl(IlvDisplay* display, const IlvRect& size, const char* filename = 0)
*The second constructor creates the Ctrl object as a child view. It has the following signature:
Ctrl(IlvDisplay* display,
IlvSystemView parent,
const IlvRect& size,
const char* filename = 0)
*The third constructor creates the Ctrl object using the existing system view. It will be used to create the ActiveX control. It has the following signature:
Ctrl(IlvDisplay* display, IlvSystemView parent, const char* filename = 0)
*The public member functions getManagerRectangle, getManagerView, and getManager provide access to the objects loaded in the control. The private member function init is called to initialize the control, that is, read the data file, associate the callbacks with the objects, and so on. Most of the code that was originally in the member function PopupManager has been transferred to this class.
Create a resource file (.rc) with ilv2data.
Using ilv2data, we create an .rc file that contains the files step1\data\ctrl.ilv and step1\data\browse.ilv. This resource file could be used in this program, but we will use it later to build the ActiveX control.
For more information on ilv2data, see Packaging Rogue Wave Views Applications.
Modify the manager.cpp file.
The file step1\manager.cpp contains only the main function, which creates an instance of IlvDisplay and an instance of the new Ctrl class.
int
main(int argc, char* argv[])
{
IlvDisplay* display = new IlvDisplay("IlvDemo", "", argc, argv);
if (!display || display->isBad()) {
if (display)
delete display;
IlvFatalError("Couldn’t create display");
return 1;
}
Ctrl* ctrl = new Ctrl(display, IlvRect(0, 0, 400, 400));
IlvMainLoop();
return 0;
}

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.