Develop ActiveX program in vc6 and release full strategy (1)

Source: Internet
Author: User

 

C # The developed ActiveX is inconvenient to use because it requires the framework to be installed. So I want to learn how to use VC ++ to develop ActiveX controls. After several days of Baidu & Google, I finally found a simple ActiveX and allowed users to download and install it through IE.

Let's talk about my development environment:

Development Tool: vc6.0

Operating System: win2003

IE version: ie7.0

 

Before the development, I checked the information about VC ActiveX development on the Internet and learned that there are two frameworks available for VC ActiveX development, one is the ATL COM structure and the other is the MFC structure. After filtering, the MFC structure is selected, because development is common. Before development, we should first know what the MFC is. I will not talk about it here. Go to Baidu. If you don't understand it after reading it, it's normal because I didn't understand it either.

It doesn't matter if you don't understand the theory, but at least you need to know how the MFC program is developed. After finding an MFC example through Baidu, It is classic. It was written by a mainland female programmer, I wrote it in a classic and detailed way. I wrote it on vc6.0 according to her example. Because the statements are written by a female, they are also more female, so I am not convenient to repost them. Here I post her blog address. I strongly recommend you follow it again, because I won't talk about the implementation of MFC in this article (I have not understood it yet, huh, huh ):

Http://sakura006.blog.hexun.com/31435400_d.html

Now let's start the journey of developing ActiveX using VC. If you have any shortcomings, please read the following link:

1. Open vc6.0 and create an MFC activexcontrolwizard project:

 

The project name can be used as needed, for example, myactivex. Click "OK" to go to the next step by default. The generated file directory is as follows:

The generated files include the source folder, header folder, and resource folder. If you still want to know what these files are, ask Baidu. Here I will only talk about the steps.

2. In fact, this project generates an ActiveX control, which is used to draw a circle on the page. Now let's check the effect first. Directly click F7. The console shows that the compilation is successful and the myactivex. ocx file is generated.

 

My project directory is under E: \ mypro, And the generated myactivex. ocx is under E: \ mypro \ myactivex \ Debug:

 

Well, it's the one with a red line in the flowers.

Let's look at the running effect.

Click the VC tool> ActiveX control test container menu. If your VC does not see this option, you may have installed the lite version:

The following dialog box is displayed:

 

Then select edit-> Insert new control to bring up the following window:

 

Then select edit-> Insert new control to bring up the following window:

 

In the list, we can see myactivex, the control we just generated. Select OK to see the effect. A circle:

 

This tool is very useful. Our custom method in ActiveX is tested in this test container:

Choose Control> invokemethods:

 

 

The following dialog box is displayed:

 

Select the method name. You can also set the parameters of the method through the parmeter list. After setting the method, click invoke to see the effect of the custom method. If only parameters are returned, the returned results are displayed in the return text box. If a dialog box is displayed, the Design dialog box is displayed. Currently, there is only one default software-related dialog box in the method. Let's see:

 

3. Add the custom method in ActiveX.

This custom method is very simple. It is to add a test (short a, short B) method and return the value of A + B. Maybe some experts will laugh at it here. It's easy to write such a simple method. Haha. It doesn't matter. After all, this article is just a work of cainiao. It is for beginners.

Select the classview option in the project directory on the left (in the red box), that is, display the class diagram:. Next we will add a custom method to ActiveX.

This custom method is very simple. It is to add a test (short a, short B) method and return the value of A + B. Maybe some experts will laugh at it here. It's easy to write such a simple method. Haha. It doesn't matter. After all, this article is just a work of cainiao. It is for beginners.

Select the classview option in the project directory on the left (in the red box), that is, display the class diagram:

Select menu View> Create Class Wizard. the dialog box is displayed:

 

 

Select the automation (custom) tab, and select cmyactivexctr class for classname, because the custom methods are generally implemented in the CTRL class file. Select Add method. The dialog box is displayed:

Enter our method name in external name. For example, my method named test has two parameters A and B, for example:

Click OK:

Continue to confirm to see if the Engineering List has changed:

 

Well, there are two more items: one test interface and one test implementation class.

Double-click the test implementation class, that is, the second red box class in the figure above, and find

Short cmyactivexctrl: Test (short a, short B)

{

// Todo: add your dispatch handler code here

Return 0;

}

Method, change it

Short cmyactivexctrl: Test (short a, short B)

{

// Todo: add your dispatch handler code here

Return A + B;

}

Oh, just convert return 0 to return a + B;

Directly F7,

 

The compilation is successful.

Now open the tool-> ActiveX control test container menu of VC (refer to the figure above ). Select the myactivex control, and then select control-> invokemethods:

Look, there is a test method in methodname, and there are two parameters a, B

 

Assign values to A and B using setvalue. Click invoke to display the result in return, 2 + 4 = 6:

 

Now we have completed this ActiveX. myactivex. ocx under the E: \ mypro \ myactivex \ DEBUG directory is our finished product. The following is the release.

From: http://flashaway.blog.163.com/blog/static/95624576200942211853685/

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.