ActiveX control is a powerful programming and development technology provided by Microsoft. It is an important part of COM component development technology. It is the third version of OLE. The biggest extension to the original ole control is the addition of the Internet function. It can be used not only in containers that support Ole controls, but also as an Internet control, directly become a part of the web page. In addition, ActiveX control, as a reusable component, is equivalent to an encapsulated code module. It communicates with applications through its methods, attributes, and events. In addition, activeX controls are independent of development languages. When using a control, you do not have to consider whether it is developed in VC or other languages such as VB. Applications communicate with the control through COM. It can be seen that ActiveX controls can be used on any software platform that supports ActiveX controls, so that controls developed by different vendors can be truly assembled together, in this way, the software production process is similar to the assembly process of various plug-ins in the hardware industry, realizing software industrialization, greatly reducing the software development cost, and greatly improving the software production efficiency, software resources are shared. ATL Technology 1) ATL is the abbreviation of ActiveX template library, which is a set of C ++ template library. With ATL, you can quickly develop efficient and concise code (proactive and slim code), and provide automatic code generation and visualization support for the development of COM components to the maximum extent. Microsoft has integrated ATL into the visual C ++ development environment since Microsoft Visual C ++ 5.0. Currently, Atl has become an important member of Microsoft standard development tools and is increasingly valued by C ++ developers. Before the emergence of ATL, there were two main methods to develop COM components: one was to use com SDK to directly develop COM components, and the other was to use the com support provided by MFC. Using com sdk to develop COM components is the most basic and flexible method. However, this development method is difficult and requires a lot of work. On the one hand, developers are required to have a deep understanding of the technical principles of COM. On the other hand, directly Using the com SDK requires developers to implement every detail of the COM application on their own to complete a lot of repetitive work. Using the com provided by MFC to develop com applications can be said to improve the degree of automation and shorten the development time on the basis of using the com SDK. MFC uses object-oriented methods to encapsulate the basic functions of COM in several C ++ classes of MFC. developers can inherit these classes to obtain the functions supported by COM. However, the development of COM components developed by MFC, especially ActiveX controls, produces considerable code redundancy and must depend on the Runtime Library of MFC to run correctly. ATL technology is an ideal technology for Developing COM components. The basic technologies used in ATL include COM, C ++ template, and C ++ multi-inheritance ). 2) The basic use of ATL to develop a com application can be divided into the following steps: (1) create a new ATL Project and configure the project options. (2) Add a new ATL class to the newly created Project and perform some initial configuration work on the class. (3) Add new interface definitions to the new ATL class according to the basic requirements of the COM application and implement corresponding interface member functions. (4) Compile the connection project and register the com application.
Use ATL technology to create ActiveX Control circlectl
1) Create an ATL Project
Use atl com Appwizard to create the ATL framework and name the project as circle. Follow the wizard prompts and follow the default settings, that is, the server type is dynamic link library (DLL ).
2) Add ActiveX controls to the ATL Project
First, select new ATL Object… from the Insert menu... Call up the ATL object wizard dialog box, select an object from the category list on the left, and select full control from the right, as shown in (1. Press next to continue. The ATL object wizard attribute dialog box is displayed. (2) on the names tab, you only need to enter circlectl in the short name edit box, and other systems will automatically give it, you can also modify it. Here we keep the system in the given State. On the attributes tab, select support isupporterrorinfo.
And support connection points check boxes. The two check boxes support error messages and connection points respectively. The Miscellaneous tab keeps the default settings. In stock properties, we add fillcolor to the support bar, after confirming, add the control to the project.
Figure 1 Figure 2
3) add custom properties for ActiveX Controls
Now we will add a basic property of the circle control, namely radius.
In workspace windows, in the Class View status, right-click the icirclectl interface and select Add property. The property type is short and the name is radius. The parameter is blank. The system automatically generates two member functions: get_radius and put_radius. Add the m_radius variable to ccirclectl to store the radius. In the ccirclectl constructor, initialize it to 50 and add * pval = m_radius to the get_radius function. In the put_radius function, add m_radius = newval; fireviewchange (); To update the view in time. For the radius attribute, we modify the draw code of the control to make it take effect.
4) modify the drawing code of the ActiveX control to implement attribute exchange
First, initialize the fill color of the drawn circle in the ccirclectl constructor, and set its initial value to red, that is, m_clrfillcolor = RGB (255, 0, 0 ).
Next, we need several global variables to save the control area information and add the following variables to circlectl. h:
Static point centerpt; Static long rectht = 0; Static long rectwd = 0; |
Then, modify the ondraw function. In this function, use the standard HDC, Hpen, hbrush, SelectObject, ellipse, and other structures and functions in Windows API to implement the painting. For example:
// Create a paint brush and a paint brush, and select a color to draw a circle Hpen = (Hpen) getstockobject (black_pen ); Holdpen = (Hpen) SelectObject (HDC, Hpen ); Hbrush = (hbrush) getstockobject (white_brush ); Holdbrush = (hbrush) SelectObject (HDC, hbrush ); Hbrush = createsolidbrush (colfore ); SelectObject (HDC, hbrush ); Ellipse (HDC, (centerpt. X-m_radius), (centerpt. Y-m_radius), (centerpt. x + m_radius), (centerpt. Y + m_radius )); |
5) add events for ActiveX Controls
Now we will add the click and rclick events to the ATL control. If you click in the rectangle area, the corresponding event is triggered. Now you want to add the click method to the icirclectlevents interface. First, right-click "icirclectlevents" in "classview" and select Add method. The following dialog box is displayed, and press set, click "OK" to add the implementation method of the click event. Add the rclick event in the same way. The parameter is consistent with the click event. Next we will implement the connection point interface iconnectionpoint for the control and the connection point container interface iconnectionpointcontainer. Compile the circle. IDL file, generate the corresponding circle. TLB, select "ccirclectl" in "classview", right-click, and select "IMPLEMENT" in the popup menu.
The connection point command. In the displayed dialog box, select the _ icirclectlevents interface. The fire_click and fire_rclick methods that take two coordinates as parameters are defined in the class. Calling these two methods can stimulate the RESPONSE event in the control.
Finally, add the code for the event to be triggered. We can process the event with the left mouse button and right-click the message response to stimulate the response. For example, the Code of the onlbuttondown function is as follows:
Word xpos = loword (lparam); // horizontal mouse Coordinate Word ypos = hiword (lparam); // vertical coordinate of the mouse Fire_click (xpos, ypos); // execute the trigger function |
Now, you can test the control in ActiveX control test container.
Use ActiveX controls on webpages
When the control is generated, the system generates a circlectl.htm file at the same time, opens the file in the VC editing environment, and adds the following VBScript between the and:
<Script language = "VBScript"> <! -- Sub circlectl_click (x, y) If circlectl. radius <100 then Circlectl. radius = circlectl. radius + 1' radius plus 1 Else Msgbox ("radius must be less than 100 !") End if End sub Sub circlectl_rclick (x, y) If circlectl. radius> = 1 then Circlectl. radius = circlectl. radius-1 'radius minus 1 Else Msgbox ("radius mustn't be less than 0 !") End if End sub --> </SCRIPT> |
Save. Open the HTM file in "My Computer", click the circle with the mouse, the radius becomes larger, and the right-click the circle radius becomes smaller.
Conclusion
This article introduces how to implement a simple circle control circlectl Based on the ATL Technology and Its Usage in Web pages. ActiveX controls, as reusable code components, are not only widely used, but also save development time. It hides a large number of implementation details and interacts with user names with simple interfaces, making it easy to use. The Research on ActiveX technology has become a hot topic and trend in today's software industry.
ActiveX control is a powerful programming and development technology provided by Microsoft. It is an important part of COM component development technology. It is the third version of OLE. The biggest extension to the original ole control is the addition of the Internet function. It can be used not only in containers that support Ole controls, but also as an Internet control, directly become a part of the web page. In addition, ActiveX control, as a reusable component, is equivalent to an encapsulated code module. It communicates with applications through its methods, attributes, and events. In addition, activeX controls are independent of development languages. When using a control, you do not have to consider whether it is developed in VC or other languages such as VB. Applications communicate with the control through COM. It can be seen that ActiveX controls can be used on any software platform that supports ActiveX controls, so that controls developed by different vendors can be truly assembled together, in this way, the software production process is similar to the assembly process of various plug-ins in the hardware industry, realizing software industrialization, greatly reducing the software development cost, and greatly improving the software production efficiency, software resources are shared. ATL Technology 1) ATL is the abbreviation of ActiveX template library, which is a set of C ++ template library. With ATL, you can quickly develop efficient and concise code (proactive and slim code), and provide automatic code generation and visualization support for the development of COM components to the maximum extent. Microsoft has integrated ATL into the visual C ++ development environment since Microsoft Visual C ++ 5.0. Currently, Atl has become an important member of Microsoft standard development tools and is increasingly valued by C ++ developers. Before the emergence of ATL, there were two main methods to develop COM components: one was to use com SDK to directly develop COM components, and the other was to use the com support provided by MFC. Using com sdk to develop COM components is the most basic and flexible method. However, this development method is difficult and requires a lot of work. On the one hand, developers are required to have a deep understanding of the technical principles of COM. On the other hand, directly Using the com SDK requires developers to implement every detail of the COM application on their own to complete a lot of repetitive work. Using the com provided by MFC to develop com applications can be said to improve the degree of automation and shorten the development time on the basis of using the com SDK. MFC uses object-oriented methods to encapsulate the basic functions of COM in several C ++ classes of MFC. developers can inherit these classes to obtain the functions supported by COM. However, the development of COM components developed by MFC, especially ActiveX controls, produces considerable code redundancy and must depend on the Runtime Library of MFC to run correctly. ATL technology is an ideal technology for Developing COM components. The basic technologies used in ATL include COM, C ++ template, and C ++ multi-inheritance ). 2) The basic use of ATL to develop a com application can be divided into the following steps: (1) create a new ATL Project and configure the project options. (2) Add a new ATL class to the newly created Project and perform some initial configuration work on the class. (3) Add new interface definitions to the new ATL class according to the basic requirements of the COM application and implement corresponding interface member functions. (4) Compile the connection project and register the com application.
Use ATL technology to create ActiveX Control circlectl
1) Create an ATL Project
Use atl com Appwizard to create the ATL framework and name the project as circle. Follow the wizard prompts and follow the default settings, that is, the server type is dynamic link library (DLL ).
2) Add ActiveX controls to the ATL Project
First, select new ATL Object… from the Insert menu... Call up the ATL object wizard dialog box, select an object from the category list on the left, and select full control from the right, as shown in (1. Press next to continue. The ATL object wizard attribute dialog box is displayed. (2) on the names tab, you only need to enter circlectl in the short name edit box, and other systems will automatically give it, you can also modify it. Here we keep the system in the given State. On the attributes tab, select support isupporterrorinfo.
And support connection points check boxes. The two check boxes support error messages and connection points respectively. The Miscellaneous tab keeps the default settings. In stock properties, we add fillcolor to the support bar, after confirming, add the control to the project.
Figure 1 Figure 2
3) add custom properties for ActiveX Controls
Now we will add a basic property of the circle control, namely radius.
In workspace windows, in the Class View status, right-click the icirclectl interface and select Add property. The property type is short and the name is radius. The parameter is blank. The system automatically generates two member functions: get_radius and put_radius. Add the m_radius variable to ccirclectl to store the radius. In the ccirclectl constructor, initialize it to 50 and add * pval = m_radius to the get_radius function. In the put_radius function, add m_radius = newval; fireviewchange (); To update the view in time. For the radius attribute, we modify the draw code of the control to make it take effect.
4) modify the drawing code of the ActiveX control to implement attribute exchange
First, initialize the fill color of the drawn circle in the ccirclectl constructor, and set its initial value to red, that is, m_clrfillcolor = RGB (255, 0, 0 ).
Next, we need several global variables to save the control area information and add the following variables to circlectl. h:
Static point centerpt; Static long rectht = 0; Static long rectwd = 0; |
Then, modify the ondraw function. In this function, use the standard HDC, Hpen, hbrush, SelectObject, ellipse, and other structures and functions in Windows API to implement the painting. For example:
// Create a paint brush and a paint brush, and select a color to draw a circle Hpen = (Hpen) getstockobject (black_pen ); Holdpen = (Hpen) SelectObject (HDC, Hpen ); Hbrush = (hbrush) getstockobject (white_brush ); Holdbrush = (hbrush) SelectObject (HDC, hbrush ); Hbrush = createsolidbrush (colfore ); SelectObject (HDC, hbrush ); Ellipse (HDC, (centerpt. X-m_radius), (centerpt. Y-m_radius), (centerpt. x + m_radius), (centerpt. Y + m_radius )); |
5) add events for ActiveX Controls
Now we will add the click and rclick events to the ATL control. If you click in the rectangle area, the corresponding event is triggered. Now you want to add the click method to the icirclectlevents interface. First, right-click "icirclectlevents" in "classview" and select Add method. The following dialog box is displayed, and press set, click "OK" to add the implementation method of the click event. Add the rclick event in the same way. The parameter is consistent with the click event. Next we will implement the connection point interface iconnectionpoint for the control and the connection point container interface iconnectionpointcontainer. Compile the circle. IDL file, generate the corresponding circle. TLB, select "ccirclectl" in "classview", right-click, and select "IMPLEMENT" in the popup menu.
The connection point command. In the displayed dialog box, select the _ icirclectlevents interface. The fire_click and fire_rclick methods that take two coordinates as parameters are defined in the class. Calling these two methods can stimulate the RESPONSE event in the control.
Finally, add the code for the event to be triggered. We can process the event with the left mouse button and right-click the message response to stimulate the response. For example, the Code of the onlbuttondown function is as follows:
Word xpos = loword (lparam); // horizontal mouse Coordinate Word ypos = hiword (lparam); // vertical coordinate of the mouse Fire_click (xpos, ypos); // execute the trigger function |
Now, you can test the control in ActiveX control test container.
Use ActiveX controls on webpages
When the control is generated, the system generates a circlectl.htm file at the same time, opens the file in the VC editing environment, and adds the following VBScript between the and:
<Script language = "VBScript"> <! -- Sub circlectl_click (x, y) If circlectl. radius <100 then Circlectl. radius = circlectl. radius + 1' radius plus 1 Else Msgbox ("radius must be less than 100 !") End if End sub Sub circlectl_rclick (x, y) If circlectl. radius> = 1 then Circlectl. radius = circlectl. radius-1 'radius minus 1 Else Msgbox ("radius mustn't be less than 0 !") End if End sub --> </SCRIPT> |
Save. Open the HTM file in "My Computer", click the circle with the mouse, the radius becomes larger, and the right-click the circle radius becomes smaller.
Conclusion
This article introduces how to implement a simple circle control circlectl Based on the ATL Technology and Its Usage in Web pages. ActiveX controls, as reusable code components, are not only widely used, but also save development time. It hides a large number of implementation details and interacts with user names with simple interfaces, making it easy to use. The Research on ActiveX technology has become a hot topic and trend in today's software industry.