"Reprint" ActiveX control development based on MFC (1)

Source: Internet
Author: User

Original: http://iysm.net/?p=114

ActiveX controls are reusable software components based on Component Object Model (COM) and are widely used in desktop and Web applications. In the VC under the development of the ActiveX control can be divided into three kinds, one is directly using the COM API to develop, this is obviously very troublesome, the programmer requirements are very high, so generally not considered; one is based on the traditional MFC, The basic functionality of COM is encapsulated in several MFC C + + classes in an object-oriented way, and developers get COM support by inheriting these classes. MFC for the vast number of VC programmers familiar, easy to learn, but the disadvantage is that the MFC package is more, so the control developed with MFC relatively large, so it is more suitable for the development of desktop Activexx control, especially with GUI interface control. The third is based on ATL, ATL can be said to be specifically oriented to COM development of a framework, using C + + template technology, at runtime do not need to rely on similar MFC programs required by the large code module, more suitable for web application development.

This article introduces the second approach, that is, the application of MFC for desktop visual control development method steps, the development environment is based on VC2005.

1. Creating a control project

After opening VC2005, we will create a project, select Visual C++-mfc on the left side of the new project page, select the MFC ActiveX control on the right, fill in the solution and project name, for example, here my project name is Activexdemo1, The solution name is Activexdemo.

Then go to the Control Wizard page, there is a run-time license on the second page of the wizard, selecting this will generate a license file at the same time as the control is generated, and other users must attach this license at the same time when using this control, which we remain in the default state, not selected.

The next page is about the naming of each part of the project, which can be customized as needed, and is not modified by default.

The next page is the extension of the selection control based on which control and some of the basic properties of the control. If the new control is based on a specific control, select the name of the control you want to inherit under the control you created, or leave none. The additional features below are selected according to the actual needs, and you can place the mouse over the options, and the description of the feature will automatically appear in the Dynamic Small prompt information window. When you're finished clicking Finish, the wizard builds the new project based on your selection.

into the development environment, we can look at the Class View first.

The Cactivexdemo1app is the main program module of our control, which defines the functions of registration (DllRegisterServer), deletion (DllUnregisterServer) of the control, and generally does not move, If necessary, we can define our own initialization and termination operation code in the InitInstance and ExitInstance, which is usually the initialization and destruction of some resources.

Caxtivexdemo1ctrl is a control class, and the control function we want to do is basically implemented in this class.

It is necessary to mention that the OnDraw function of the parent class is overridden in this class, as in the following two lines of code:

Pdc->fillrect (RcBounds, Cbrush::fromhandle (hbrush) getstockobject (White_brush));

Pdc->ellipse (RcBounds);

That is, an ellipse is drawn on the control, and the actual control development can be modified to override this function to draw the control interface.

Caxtivexdemo1proppage is a property page class that implements a dialog box that sets the properties of a control at development time.

Activexdemo1lib is a library node that provides the client program with properties, methods, and interfaces for events that might respond, which are used when adding controls to these functions.

The Cactivexdemo1app is the main program module of our control, which defines the functions of registration (DllRegisterServer), deletion (DllUnregisterServer) of the control, and generally does not move, If necessary, we can define our own initialization and termination operation code in the InitInstance and ExitInstance, which is usually the initialization and destruction of some resources.

Caxtivexdemo1ctrl is a control class, and the control function we want to do is basically implemented in this class.

It is necessary to mention that the OnDraw function of the parent class is overridden in this class, as in the following two lines of code:

Pdc->fillrect (RcBounds, Cbrush::fromhandle (hbrush) getstockobject (White_brush));

Pdc->ellipse (RcBounds);

That is, an ellipse is drawn on the control, and the actual control development can be modified to override this function to draw the control interface.

Caxtivexdemo1proppage is a property page class that implements a dialog box that sets the properties of a control at development time.

Activexdemo1lib is a library node that provides the client program with properties, methods, and interfaces for events that might respond, which are used when adding controls to these functions.

"Reprint" ActiveX control development based on MFC (1)

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.