Operation and Maintenance
Windows Operation and Maintenance
Win32 SDK Basics (6) Detailed explanation of the window class search process and related APIsWin32 SDK Basics (6) Detailed explanation of the window class search process and related APIs
1. The search process of window classes
In the previous article, we introduced the three window classes of the windows system - system window class, Global window class and local window class. Each window class has a different scope in the operating system, and the window class name registered in each scope cannot be repeated. When creating a window, it is often searched according to the window class name in the system, global, and local scopes. The search process is summarized as follows:
(1) The operating system searches based on the incoming window class name. Now search in the local window class. If found, execute step 2. If not found, execute step 3.
(2)Compare the local window class with the HINSTANCE variable passed in when creating the window. If they are found to be equal, it means that the created and registered windows are in the same module, and the created window is returned. If not equal, continue to step 3.
(3)Search in the global window class of the application. If found, perform step 4. If not found, perform step 5 steps.
(4) Use the found window class information to create a window and return.
(5) Search in the system window class. If it is found, create the window. If it is not found, the window creation fails.
2. Register the window classAPI RegisterClass and RegisterClassEx
RegisterClass and RegisterClassEx can be used to register window classes. Their two prototypes are as follows:
ATOM WINAPI RegisterClass( _In_ const WNDCLASS *lpWndClass ); ATOM WINAPI RegisterClassEx( _In_ const WNDCLASSEX *lpwcx );
It can be seen from the API prototype that the two prototypes are as follows: The difference mainly lies in the parameters received, which is the window class we need to register. The two window classes are declared as follows:
typedef struct tagWNDCLASS {
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
} WNDCLASS, *PWNDCLASS;typedef struct tagWNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;As you can see from the above code, the main difference between the two window classes structure is that WNDCLASSEX contains The structure size of the cbSize window and the small icon handle of the hIconSm window. Please refer to MSDN for the meaning of other parameters.
3. Get registered window informationGetClassInfo
GetClassInfo() APIcanGet registered The window information, its function prototype is as follows:
BOOL WINAPI GetClassInfo( _In_opt_ HINSTANCE hInstance, _In_ LPCTSTR lpClassName, _Out_ LPWNDCLASS lpWndClass );
hInstance—— is to set the search scope, if set to NULL, will be searched from three scopes: system, global and local.
lpClassName - is the name of the window class to be found.
lpWndClass - The address of the passed in WndClass structure variable, used to receive window class information.
Let’s find the window information of the Button class created above:
WNDCLASS wc; if (GetClassInfo(NULL, "Button", &wc) == false) MessageBox(NULL,"GetClassInfo Faile",NULL,NULL);
Let’s set a breakpoint , check the obtained Button window class information:
4. Uninstall the window classUnregisterClass
We can unregister the registered window class through UnregisterClass. Its prototype is as follows:
BOOL WINAPI UnregisterClass( _In_ LPCTSTR lpClassName, _In_opt_ HINSTANCE hInstance );
lpClassName - is the name of the window class to be uninstalled.
hInstance —— is to set the search scope. If it is set to NULL, it will search from three scopes: system, global and local.
The following code uninstalls the registered Button window class:
if (UnregisterClass("Button",NULL) == false)
MessageBox(NULL, "UnregisterClass Faile", NULL, NULL);The above is the detailed content of Win32 SDK Basics (6) Detailed explanation of the window class search process and related APIs. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),





