Table of Contents
1. The search process of window classes
2. Register the window classAPI RegisterClass and RegisterClassEx" > 2. Register the window classAPI RegisterClass and RegisterClassEx
Get registered window informationGetClassInfo" >3. Get registered window informationGetClassInfo
Uninstall the window classUnregisterClass" >4. Uninstall the window classUnregisterClass
Home Operation and Maintenance Windows Operation and Maintenance Win32 SDK Basics (6) Detailed explanation of the window class search process and related APIs

Win32 SDK Basics (6) Detailed explanation of the window class search process and related APIs

Jun 06, 2017 am 09:44 AM

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
);
Copy after login

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;
Copy after login
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;
Copy after login

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
);
Copy after login

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);
Copy after login

        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
);
Copy after login

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);
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Windows 11 22H2 brings mica/acrylic design to more Win32 desktop apps Windows 11 22H2 brings mica/acrylic design to more Win32 desktop apps Apr 14, 2023 pm 04:58 PM

Windows 11’s native apps (like File Explorer) and other shell apps use rounded corners and Fluent Design elements (like Acrylic) by default. In addition to rounded corners, another important design feature of Windows 11 is materials like mica, which aligns the background color of apps with the desktop. Mica is similar to acrylic but works slightly differently. As Microsoft describes it, Windows Mica Materials creates "color hierarchy by aligning backgrounds with apps

Trojan/win32.casdet Rfn in Windows 11 Trojan/win32.casdet Rfn in Windows 11 Apr 14, 2023 pm 02:49 PM

Antivirus software may sometimes display a warning stating Trojan/win11.casdet rfn on Windows 32 laptops. It indicates that the PC is infected with Trojan malware, causing it to malfunction. Fortunately, there are some possible ways to fix this problem, as explained below. Additionally, you may be interested in our detailed guide on whether cdn.districtm.io is a pop-up/virus/malware or not. What is Trojan/win32.casdet rfn? Trojan/win32.casdet rfn is a severe Trojan virus infection that can overrun the system and kill its processes, making it easy

What is the difference between win32 and win64 What is the difference between win32 and win64 May 29, 2023 pm 05:22 PM

The difference between win32 and win64 is: 1. win32 refers to the 32-bit environment of the Microsoft Windows operating system, and win64 refers to the 64-bit version of the Microsoft Windows operating system, which is more stable and faster than the 32-bit version; 2. win32 supports up to 2G of memory. win64 must have more than 4G of memory; 3. win64 supports 64-bit processors, but win32 cannot fully support it; 4. win32 pursues simplicity, while win64 pursues performance.

Microsoft begins testing new OneNote design for Windows 11 Microsoft begins testing new OneNote design for Windows 11 Apr 19, 2023 pm 08:01 PM

Back in August 2021, Microsoft promised that OneNote on Windows 10 and Windows 11 would receive a series of major feature updates in the coming months, as the tech giant unifies multiple versions of the note-taking app into a single one. part of the efforts of customers. OneNote has undergone many changes over the past few years. In 2018, when Microsoft really wanted people to use its UWP version of OneNote, the company stopped bundling the original and feature-rich version of OneNote with preinstalled Office apps. Instead, Microsoft has only provided a UWP client and added new features for modern versions. Microsoft later changed

Microsoft releases fix for Behavior:Win32/Hive.ZY error in Windows Defender Microsoft releases fix for Behavior:Win32/Hive.ZY error in Windows Defender Apr 28, 2023 pm 04:01 PM

A Microsoft official confirmed widespread reports that Google Chrome, ChromiumEdge, Discord and several other applications were flagged as "Behavior:Win32/Hive.ZY" by Microsoft's built-in antivirus software "WindowsDefender". The tech giant confirmed in a statement that it is working on a fix that will be rolled out to everyone in the next few hours. So what exactly is "Behavior:Win32/Hive.ZY"? According to a document posted on Microsoft's security portal, any file marked "Behavior:Win32/Hive.ZY" is

What's new in Microsoft Store on Windows 11? What's new in Microsoft Store on Windows 11? Apr 28, 2023 pm 06:13 PM

Microsoft is putting a lot of new features into the Microsoft Store. These will benefit both end users and developers as the company continues its efforts to make the Store better for everyone who uses Windows. One of the biggest highlights of these changes will be the new "Restore Apps" feature in Microsoft Store on Windows 11. It will be connected to the user's Microsoft account, so after logging into a new Windows 11 PC, they can automatically restore the application with just a few clicks. "To make it easier for customers to quickly and seamlessly transition to their new PCs, we will soon be introducing

How to fix Windows Defender behavior: Win32/Hive.ZY alert How to fix Windows Defender behavior: Win32/Hive.ZY alert May 06, 2023 am 08:04 AM

Many Windows 11 and 10 users are troubled by seeing warning notifications from Windows Defender stating that the threat "Behavior: Win32/Hive.ZY" has been detected. According to reports, this Windows Defender warning or alert is triggered when users try to open some commonly used applications such as Google Chrome or Chromium Edge, Whatsapp, Discord, and Spotify. Even if you have blocked this threat on your PC, it will pop up with a message MicrosoftDefenderAntivi the next time you open this affected application

Win32 graphic design software Canva launches free AI tool to challenge giant Adobe Win32 graphic design software Canva launches free AI tool to challenge giant Adobe Mar 05, 2024 pm 04:34 PM

According to recent news, Canva has launched a series of AI image tool functions in an attempt to compete with Adobe's Firefly. It aims to simplify the content creation process in the workplace, making it easier and more efficient for non-design professionals to create content, and allowing graphic designers to Focus on mission-critical tasks and challenge Adobe's dominance in the market. According to reports, Canva’s Visual Worksuite has integrated the new BrandHub, which aims to provide users with a set of tools to help them ensure consistency with their organization’s visual identity. Users can use this tool to create a BrandKit (brand IP toolkit) that contains company cultural information (such as LOGO, fonts, colors and unified design style).

See all articles