MFC ActiveX Control

Source: Internet
Author: User

ActiveX control is a reusable software component based on the Component Object Model (COM). It supports a wide range of OLE functions and can be customized to meet the needs of a variety of software. ActiveX controls are intended for Common ActiveX Control containers and web pages on the Internet. You can use the MFC introduced here or use the Active Template Library (ATL) to create ActiveX controls.

ActiveX controls can describe themselves in their own windows, respond to events (such as clicking the mouse), and manage them through interfaces including properties and methods, these attributes and methods are similar to those in automation objects.

These controls can be developed for many purposes (such as database access, data monitoring, or graphic rendering. In addition to portability, ActiveX controls also support features not previously available, such as compatibility with existing OLE containers and the ability to integrate their menus with the menus of OLE containers. In addition, ActiveX controls fully support automation, allowing controls to publish read/write attributes and a set of methods that can be called by control users.

You can create a window-free ActiveX Control and a window control that is only created during activity. Window-free controls accelerate the display of applications and include transparent controls and non-rectangular controls. You can also asynchronously load properties of ActiveX controls.

ActiveX control is implemented as an in-process server (usually a small object), and an in-process server can be used for any OLE container. Note that all functions of the ActiveX control are available only when it is used in the OLE container of the ActiveX control. This type of container (later called "control container") can be used to operate the control by using the properties and methods of the ActiveX control, and receive event notifications from the ActiveX control. This interaction is demonstrated.

Interaction between ActiveX Control containers and window ActiveX Controls

ActiveX control basic components

ActiveX controls use several programming elements to effectively interact with control containers and users. These elements are the COleControl class, a group of events that trigger functions and scheduling ing.

Each ActiveX control object you develop uses its MFC base classCOleControlInherits a set of powerful functions. These features include Local activation and automated logic.COleControlProvides the same functions as the MFC window object for the control object and the ability to trigger events.COleControlYou can also provide window-free controls. The windowless control depends on the help of its container to obtain some functions provided by the window (Mouse capture, keyboard focus, scroll), but the display speed is much faster.

Because the control class is fromCOleControlIt inherits the ability to send or "Trigger" messages (called events) to control containers when certain conditions are met. These events are used to notify the Control container when an important event occurs in the control. By attaching parameters to an event, you can send other information about the event to the control container.

The final element is the scheduling ing, which is used to expose a group of functions (called methods) and features (called attributes) to the control user ). Properties allow control containers or control users to operate controls in various ways. You can change the widget's appearance, modify some values of the widget, or generate a control request (such as a specific data segment maintained by the Access Control ). This interface is determined by the control developer and defined by "Class View. Interaction between controls with windows and ActiveX Control containers

When a control is used in a control container, the control uses two mechanisms for communication: Public attributes and methods, and event triggering. Demonstrate the implementation methods of these two mechanisms.

Communication between ActiveX Control containers and ActiveX Controls

It also explains how controls handle other OLE interfaces besides automation and events.

All communication between the control and the container is performedCOleControlRun. To process some container requests,COleControlCall the member functions implemented in the control class. All methods and some attributes are processed in this way. You can also callCOleControlTo initialize the communication with the container. Events are triggered in this way.

ActiveX Control activity status and inactive status

Controls have two basic states: active and inactive. Traditionally, the two States are distinguished based on whether the control has a window. The active control has a window, but the inactive control does not. After windowless activation is introduced, this difference is no longer common, but still applies to many controls.

When a windowless control is active, it calls Mouse capture, keyboard focus, scroll, and other window services from its container. In addition to creating a control that waits until it is activated to create a window, you can also provide mouse interaction for a non-active control.

When a widget with a window is active, it can fully interact with the control container, user, and Windows. Demonstrates the communication path between ActiveX controls, control containers, and operating systems.

Windows Message Processing in window ActiveX Control (active)

Serialization

The ability to serialize data (sometimes called persistence) allows the control to write its attribute values to persistent storage. In this way, you can re-create the control by reading the object status from the storage.

Note that the control is not responsible for obtaining access to the storage media. On the contrary, the control container is responsible for providing storage media for the control for use when appropriate. For more information about serialization, see the article "MFC ActiveX Control: serialization. For information on optimizing serialization, see optimizing persistence and initialization in ActiveX Control: optimization.

Install ActiveX controls and tools

When installing Visual C ++, if ActiveX controls are selected during installation (they are selected by default ), the system automatically installs the MFC ActiveX control class and releases and debugs the DLL when the ActiveX control is running.

By default, ActiveX control classes and tools are installed in the following subdirectories under/Program Files/Microsoft Visual Studio. NET:

  • /Common7/Tools

    Include the test container file (tstcon32.exe and its help file ).

  • /Vc7/atlmfc/include

    Contains the files required to develop ActiveX controls using MFC

  • /Vc7/atlmfc/src/mfc

    Contains the source code of the special ActiveX control class in MFC

  • /Vc7/atlmfc/lib

    Contains the library required for developing ActiveX controls using MFC

Examples of the MFC ActiveX control are also provided.

 

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.