[Translation] Security subclass in Win32 (4)

Source: Internet
Author: User

Security subclass in Win32 (1)

Global subclass

Global subclass is similar to instance subclass. Applications call FunctionsSetClassLongGlobal subclass of a window class. Just like in the instance subclass, the application also needs the address of the subclass function, in addition, this subclass function must be exported in the application or DLL module definition file.

To globally subclass A window class, an application must have a window instance of this class. To obtain a window instance of this class, most applications create a window of the window class to be globally subclass. When the application wants to remove the subclass, there must also be a window handle, which should belong to the window class to be subclass by the application. Therefore, it is good to create and save a window specially. If an application needs to create a window instance of the window class to be subclass, the window instance is usually invisible. After a window handle of the correct type is available, the application can use the window handle, GCL_WNDPROC flag (defined in WINDOWS. H), and the address of the new subclass function as the parameter to call the function.SetClassLong, This function returnsDWORDValue, which is the original window process address of the window class. The usage of the original window process address in the global subclass is the same as that in the instance subclass. The window message is also called by the function like in the instance subclass.CallWindowProcThe process passed to the original window. The application can callSetClassLongFunction to remove the subclass from the window class. In this case, you need to pass the parameter to the window instance handle of the original window process address, GCL_WNDPROC sign, and the quilt window class. Applications that globally subclass A control must remove the subclass when the application ends.

The following code demonstrates the global subclass of an edit box control and the removal of subclasses for it:

Long far pascal SubClassFunc (HWND hWnd, UINT, Message, WORD wParam, LONG lParam );
FARPROC lpfnOldClassWndProc;
HWND hEditWnd;

//
// Create an edit control and subclass it.
// Notice that the edit control is not visible.
// Other details of this particle edit control are not important.
//
HEditWnd = CreateWindow ("EDIT", "EDIT Test ",
WS_CHILD,
0, 0, 50, 50,
HWndMain,
NULL,
HInst,
NULL );

LpfnOldClassWndProc = (FARPROC) SetClassLong (hEditWnd, GCL_WNDPROC, (DWORD) SubClassFunc );
.
.
.
//
// To remove the subclass:
//
SetClassLong (hEditWnd, GWL_WNDPROC, (DWORD) lpfnOldClassWndProc );
DestroyWindow (hEditWnd );

Potential Defects

Global subclasses have the same limitations as instance subclasses. Applications should not try to use them unless they explicitly know how to use the additional bytes of the window class and window instance during the original window process. If the data must be associated with a window, you can use the window attribute list as described in the instance subclass.

In Win32, global subclasses do not take effect for window classes in any other process or window instances created from these classes, which is a major change for the Win16 environment. In the system, Windows saves the Window class information for each Win32 process separately. For more information, see the Technical Article Windows Classes in Win32 in MSDN. Currently, global subclasses cannot take effect for other processes, which is a useful technology for developers. In Win16, global subclass applies to every window instance of the quilt-type window class: not only applications that perform subclass operations, it is disappointing to include the entire system. This is usually the effect that the application does not want to achieve, so the application has to use more inconvenient, not easy to use to change the window instance behavior created from the System window class. However, in Win32, it is very easy to use global subclass.

Security subclass in Win32 (5)

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.