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!
![[Solved] How to Fix the Lost Ark EAC Offline Error on PC? - MiniTool](https://img.php.cn/upload/article/001/242/473/174637740950668.png?x-oss-process=image/resize,p_40)
If you encounter the Lost Ark EAC Offline Error on your PC, you don’t need to worry. This post from php.cn is worth reading. It provides some effective solutions for you to fix this error.

How do you install a new Canon printer driver for MG2900 series? To make sure your printer works properly, installing a driver is necessary and php.cn will give you a detailed guide on Canon MG2900 driver download, install & update.

Microsoft Vulnerable Driver Blocklist is a very useful feature in Windows Security. It can protect your computer against vulnerable applications. However, when this option grayed out or not working, your system might be vulnerable. Fortunately, this

What is thumbnail cache and how to clear thumbnail cache? php.cn Website offers you this detailed tutorial to know how to clear thumbnail cache hand by hand. Does your computer often seem sluggish? Come on and follow us!

Microsoft has made a program called the Photos application with basic functions. When using it, you may encounter some issues. Microsoft Video Editor not exporting on Windows 11 is one of the issues. This post from php.cn introduces how to fix it.

You can activate Windows 11/10 by using a Windows digital license. This post explains how to get a Windows 11/10 digital license and use it to activate your Windows 10/11 computer. For more useful computer tips, tricks, and tools, you can visit php.c

144Hz monitor only showing 60Hz? How to set monitor to 144Hz or how to make sure your monitor is running at 144Hz? After reading this post from php.cn, you know what you should do in Windows 10/11. Let’s go to look through the following ways.
![[Compare] - Steam Deck vs Nintendo Switch: Which One Is Better? - MiniTool](https://img.php.cn/upload/article/001/242/473/174637699060200.jpg?x-oss-process=image/resize,p_40)
What are the differences between Steam Deck and Nintendo Switch? This post from php.cn helps you realize each device so you can make an informed purchasing decision. Now, continue to read to get more details about Steam Deck vs Switch.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

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

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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),
