Develop dynamic web pages based on ActiveX Controls

Source: Internet
Author: User

Original article address:

Http://softsky.jblog.cn/160063.shtml

Web page development involves three types: static Web pages, semi-dynamic web pages, and client-side dynamic pages. This article focuses on the development of dynamic real-time pages based on ActiveX control.

The ActiveX control is used to embed the control into the home page. When a user accesses the home page through a browser, the control on the home page is downloaded and registered on the user's machine, you can run it on your browser later. After the control is downloaded once, it will reside on the user's local machine. The next time you visit the same home page, you can not download the control, but directly run the user's local control. The control container is the browser, and you do not need to call the properties or methods of the control through the browser. Therefore, developing web-oriented ActiveX controls is easier than developing desktop controls. What is complicated is how to embed the controls into the home page so that users can browse them normally. The following describes the problem.

Add ActiveX controls to the web page
On the HTML page, you can use the ActiveX control to add the control to HTML, download the control to the user, and install the control on the user's machine. If it is only for IE users, it is relatively simple to insert ActiveX controls into HTML; if both IE and Netscape users are taken into account, more work is required. As you know, HTML files are composed of texts and various tags. ActiveX controls use <Object> to mark IE in HTML, which has several important parameter features:

1. ID: provides an ID name for the control and an access method for HTML code.

2. classid: the unique UUID of the control, which indicates the object to be loaded by IE. If you use a developed control, its classid can be searched by calling the application Regedit in Win95 or NT. Run the program from the Start menu and expand the hkey_classes_root item. You can see the Registry in alphabetical order and find the name of the control to be used, such as wclnt. When you expand the program, you can see a CLSID folder, it is the classid of the control.

If you develop a Control Using VC, the uuid can be found in the odl (Object Description Library) file of the ActiveX control project. You can locate the uuid of a specific control by viewing the class information comments of the control, for example, to find the uuid of the cmycontrol control, you need to find the following code:

// Class information for cmycontrol

[UUID (051c4748-1262-11d2-87c1-00a024d948fb ),

Licensed,

Helpstring ("cmycontrol"), control]

The content following the uuid is the uuid of the control.

3. codebase: If no current version of the control is available on the user's machine, this parameter indicates where the user's browser can find the control to download and the latest version number. after the control is modified, you can change the version number to force the user to download it again.

4. Param: This tag is used to set the initial property value of the control. It has two features: Name and value, namely, attribute name and attribute value.

In addition, there are some tags, such as: width indicates the width occupied by the control, height indicates the height, etc. In general, the HTML code of such an insert control is very similar to the HTML code of inserting a Java applet.

The following is an example of HTML code with ActiveX controls embedded:

 

Id = "cmycontrol"

Classid = "CLSID: 051c4748-1262-11d2-87c1-00a024d948fb"

Codebase = "http://www.mysite.com.cn/ocxdir/mycontrol.ocx?version="

Width = 400

Height = 200

Align = center

Hspace = 0

Vspace = 0

>

If you want the control to run in Netscape, in addition to adding plug-ins to Netscape, HTML also needs to add some additional tags. In the following example, the embed segment is added to Netscape. If you use MFC to develop the OCX control, a few users will download the corresponding mfc dll in addition to downloading the ocx file during the first access, and the download volume will increase, in this case, you can package related files on the server to a cab file that can be decompressed and installed on the client. The modified HTML code snippet is as follows:

<Align = "center" classid = "CLSID:

7bca18c6-2178-11d2-87c1-00a024d948fb"

Width = "1200" Height = "900" id = "marquee"

Codebase = "http: // 218.168.188.188/scadaweb/

Wclnt. Cab # version =, ">

<Embed align = "center" classid = "CLSID: 7bca18c6-2178-11d2-87c1-00a024d948fb"

Width = "1200" Height = "900" id = "marqueequot ;"

Codebase = "http: // 218.168.188.188/scadaweb/

Wclnt. ocx # version ="

Type = "application/oleobject">

Real-time dynamic page Implementation Scheme
Real-time dynamic pages are mostly generated in applications that require automatic updates of real-time data, such as grid monitoring and stock market monitoring. The specific requirement is: you only need to select the chart you want to browse, but you do not need to intervene in the operation, the chart can be updated continuously based on real-time data, users can always observe the latest situation.

To implement the above functions, there are two structures: one is to set up an intermediary server, which serves as the intermediary for information exchange between controls and the background system; the other is to set up an intermediary server, however, a data interface is provided on the backend server that provides real-time data for control communication. The control can obtain the current real-time data from the backend server at regular intervals. There are two ways to provide data: one is that the client sends requests to the server at a scheduled time, specifying the required real-time data, after receiving the request, the server sends the dynamic data that meets the request to the corresponding customer. The other is that the client only requests once and the server regularly transmits the real-time data that meets the request to the client, wait until the customer changes the chart to be displayed or stops refreshing. The above schemes have their own advantages and limitations. In the application, you can consider the actual situation to adopt the corresponding scheme.

The workflow is as follows: the user first downloads a webpage containing ActiveX controls from the Web server, and then registers and runs the control on the client, and uses Winsock as the intermediary server or directly provides real-time information through the network, for example, the stock information network is connected to Obtain Dynamic Real-time Data and refresh the display. In this system, the customer has two lines to obtain information, one is the connection with the Web server, access the home page from this online user, and the other is the connection between the control and the background information network, users can access real-time data from this line. The next line is built with Winsock. The transmission speed is much higher than that of the previous line, and the control is flexible and efficient. It does not compete with the home page for resource download. Through this line, users can even transmit remote control information for remote control.

Develop ActiveX controls using MFC
This control was developed using vc5.0 and features are highly scalable. Theoretically, this control can be implemented by an independent vc5.0 program. For example, the control can be used to draw a browser directly, and OpenGL and other libraries can be used, powerful graphic and image functions. In theory, the real-time data refresh frequency can reach a millisecond level. You can use the mouse to perform various interactive operations, such as rotation and scaling. Figure 2 is a GL image with a zoom toolbar. If you are watching on a computer, you can see that these 3D images are constantly rotating.

It should be said that a good development tool can use API programming or the ATL template library directly. Developing ActiveX controls using MFC is not a good choice, because the control operation requires the support of mfc dll. If the user does not have these class libraries on the machine (this is rare, but does exist), it will take some time to download them for the first time. However, for developers familiar with MFC, these problems can be ignored in terms of convenience provided by MFC.

Because vc5.0 provides a lot of convenience for ActiveX control development, developing an ActiveX control is not as difficult and complex as many people think. Through the Appwizard of VC 5.0, the main class that implements the control is derived from the colecontrol class, which is a subclass of cwnd, so you can program the main class like the window class. To implement the functions mentioned above, you must first reload the ondraw function to add the objects to be drawn and the Winsock class (csocket or casyncsocket) to implement communication with the backend data server. If you need to use OpenGL to draw a variety of three-dimensional graphs, You need to initialize the GL environment. Other tasks are to control program scheduling so that all functions can work normally and communicate with other functions normally. In addition, the backend server program must also add interfaces corresponding to the control.

After such a program is compiled, it becomes a web control with the suffix OCX. Place the OCX into the home page according to the method described above, and the basic work is completed.

To sum up, ActiveX control developed by vc5.0 is used for Web browsing. It has the following features:

1. Use the Winsock communication mechanism, which features fast speed, flexible control, and high efficiency;

2. The control is compiled using vc5.0 and features are highly scalable;

4. Although it takes a little time to download the control for the first time, it is registered on the user's machine after the download, and can be called directly in the future, with high speed and efficiency;

5. ActiveX technology is the top priority of Microsoft's development. It has become the trend of current software development and has a broad development space;

6. The system is developed using VC, and the existing system compiled using C language can be used, greatly reducing the development workload.

 

About the discussion:

Recently, I have been learning to write ActiveX controls. I use VB to write, now it seems VC is also good. However, I wrote a huge package into a cab. I don't know what to do.
In addition, an error occurred while saving the data submitted by the user to the database on the server using ActiveX. The database file cannot be found and it is found locally! What should I do?

You can see your blog is very fond. Hope you can learn from me.
My QQ account is 9480590. Do you have QQ?

The following is the reply from the blog owner:
If you want to upload data to the server, you have to connect to and upload the server in the control. If you only want to upload data, which of the following cannot be done, because your operations are relative to local operations, in fact, there is no connection with the server. I do not know.
QQ: 274043505

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.