What does it mean to get the window handle of the screen
It will be easier to understand if you know what a handle is
Is to get the identification code of this window
The handle is a unique identifier used to distinguish various memory objects. It is a 32-bit integer.
Some are unique to the entire system (such as window handles), and some are unique to the current process or thread
(such as thread handle, the global one has another identifier).
It can be divided into many types in detail, all starting with H. When using it in VB, all use Long.
Common ones include window handle (HWND), device description table handle (HDC), memory handle (HMEM),
File handle, process handle, thread handle, pen type handle (HPEN), font handle (HFONT),
Region handle (HRGN) and so on.
When applying for a handle, resources are occupied, which are divided into three categories: SYSTEM, USER, and GDI.
The resources of WINDOWS are fixed and do not expand with the expansion of memory, so you must release them after use
put.
>
If you only use VB's own code, you will generally not use handles, but if you use API functions,
Most will use it.
In the Windows system, handles (I have always felt that this word is particularly awkward to translate) are divided into three categories: Kernel
Handle, UserHandle and application-defined Handle.
KernelHandle is actually the pointer table index of the Kernel object in the process. The Kernel object includes the process and file
Pieces, signals, etc. However, in order to hide the fact, MS generated a so-called Obsfucator value when the system started.
(actually it should be Obfuscator, MicrosoftBugs(R):), after generating the Handle, differentiate the Handle from this value
or is returned to the application, so the Handles you see are all large and meaningless numbers. These
Handle and index objects are jointly managed by KRNL32.DLL and VMM32.VXD, so they are called Kernel
Handle.
UserHandle is used to mark objects such as windows and DCs. They are real pointers, but they do not point to objects
At the beginning of, there is an offset. Again, these objects are managed by USER32.DLL.
The third type of Handle is just some indexes customized by the application. The specific meaning is related to the application
How to get the console window handle
1. Call GetConsoleTitle() to save the current console window title.
2. Call SetConsoleTitle() to change the console title to a unique title.
3. Call Sleep(40) to ensure that the window title has been updated.
4. Call FindWindow(NULL, uniquetitle) to obtain HWND. This call will return HWND. If the operation fails, NULL will be returned.
5. From step 1, to restore the original window title retrieve the value call SetConsoleTitle().
The HWND of the test result should be tested. For example you can test whether the returned HWND corresponds to the current process calling GetWindowText() on the HWND and compare the result to GetConsoleTitle().
Sample code
The following function retrieves the current console application window handle (HWND). If this function succeeds, the return value is a handle to the console window. If this function fails, the return value is NULL. Some error checking is omitted for brevity.
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated
// WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original
// WindowTitle.
// Fetch current window title.
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
// Format a "unique" NewWindowTitle.
wsprintf(pszNewWindowTitle,"%d/%d",
GetTickCount(),
GetCurrentProcessId());
// Change current window title.
SetConsoleTitle(pszNewWindowTitle);
// Ensure window title has been updated.
Sleep(40);
// Look for NewWindowTitle.
hwndFound=FindWindow(NULL, pszNewWindowTitle);
// Restore original window title.
SetConsoleTitle(pszOldWindowTitle);
return(hwndFound);
}
50 points How to get the handles of all windows on the desktop
#include
#include
using namespace std;
//Callback function for EnumWindows
BOOL CALLBACK EnumProc(HWND hwnd,LPARAM lparam)
{
vector
pvec->push_back(hwnd);
return TRUE;
}
void main()
{
vector
EnumWindows(EnumProc,(LPARAM)&vec);
}
This is written in a win32 console program project. If you want to use it under MFC, you only need to include
#include
EnumProc is defined before, just add the two sentences in the main function to the button response function.
I tested here and got 407 handles
The above is the detailed content of What does a screen window handle mean?. For more information, please follow other related articles on the PHP Chinese website!

This article addresses the Windows "INVALID_DATA_ACCESS_TRAP" (0x00000004) error, a critical BSOD. It explores common causes like faulty drivers, hardware malfunctions (RAM, hard drive), software conflicts, overclocking, and malware. Trou

Article discusses editing Windows Registry, precautions, backup methods, and potential issues from incorrect edits. Main issue: risks of system instability and data loss from improper changes.

Article discusses managing Windows services for system health, including starting, stopping, restarting services, and best practices for stability.

What does the drive health warning in Windows Settings mean and what should you do when you receive the disk warning? Read this php.cn tutorial to get step-by-step instructions to cope with this situation.

This article identifies ene.sys as a Realtek High Definition Audio driver component. It details its function in managing audio hardware, emphasizing its crucial role in audio functionality. The article also guides users on verifying its legitimacy

This article addresses the failure of the Windows asio.sys audio driver. Common causes include corrupted system files, hardware/driver incompatibility, software conflicts, registry issues, and malware. Troubleshooting involves SFC scans, driver upda

Article discusses changing default apps for file types on Windows, including reverting and bulk changes. Main issue: no built-in bulk change option.

The article explains how to use the Group Policy Editor (gpedit.msc) in Windows for managing system settings, highlighting common configurations and troubleshooting methods. It notes that gpedit.msc is unavailable in Windows Home editions, suggesting


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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools