[Translation] Security subclass in Win32 (1)

Source: Internet
Author: User

Although the topic about subclass is somewhat old, it is still a powerful technology for Windows development, in the MFC kernel, or even. net kernel is inseparable from it, and it is hoped that this serialization can be helpful to Windows developers.

Original article title: Safe subclassing in Win32
By Kyle marsh
Msdn Technical Group

Click here to view the original article

Summary

This article describes Win32 Subclass in the Environment describes how it works and the rules that must be followed to implement security subclass. This article covers instance subclass and global subclass. Superclassization is introduced as an optional alternative to global subclass.
Slave Win16 To Win32 , Subclass is not significantly changed, but in Win32 , An applicationProgramWe still need to follow several new subclass rules. The most important (and most obvious) is that an application cannot subclass windows or classes belonging to another process, Unless a workspace is provided to the applicationThis rule cannot be broken.

Subclass Definition

subclass is such a technology, it allows an application to intercept messages sent to another window. An application intercepts messages that belong to another window to add, monitor, or modify the default behavior of that window. Subclass is an effective way to change or expand an existing window without re-development. You want to obtain the window classes of predefined controls (button controls, edit controls, list controls, drop-down list controls, static controls, and scroll bar controls) A convenient way to modify some of their behaviors is to subclass them. For example, if you press enter the dialog box is closed. By subclass editing controls, an application can have an edit control that can insert carriage return and line feed to text without closing the dialog box, the application does not need to develop an editing Control for this special need.

Subclass basis

The first step in creating a window is to fill in Wndclass Structure, and call Registerclass Function to register a window class. Wndclass One of the members of the structure is the window process address of the window class. When a window is created, 32 Bit version Microsoft Windows The operating system will retrieve Wndclass Structure, and copy it to a new window information structure. When a message is sent to this window, Windows Call the Window Process of the window through the address in the window information structure. To subclass a window, you must replace the original window process address with a new window process address so that the new window process can receive all messages sent to the original window process.
When an application subclass a window, it can take three actions on messages: (1) The process of passing the message to the original window; (2) Modify the message and pass it to the original window; (3) Messages are no longer transmitted.
When an application subclass a window, it can decide under what circumstances to respond to the received message. The application can pass the message to the original window before or (and) then process the message.

Subclass type

There are two subclass types, they areSubclassAndGlobal subclass..

An instance subclass is a subclass of an independent window information structure. After an instance is subclass, only messages belonging to a specific window instance are sent to the new window.
Global subclass replaces a window class Wndclass Window Process address in the structure. All windows created using the window class after this have the replaced window process address. Global subclass is only valid for the windows created after the subclass takes effect. If there is any window created using this global subclass before the subclass is made, these existing windows are not classified into quilts. If the application wants to make the subclass take effect for these existing windows, the application must subclass each existing window class instance.

Security subclass in Win32 (2)

Related Article

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.