Home Computer Tutorials Computer Knowledge What does a screen window handle mean?

What does a screen window handle mean?

Jan 23, 2024 pm 09:24 PM
Get form handle

What does a screen window handle mean?

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 = (vector*)lparam;

pvec->push_back(hwnd);

return TRUE;

}

void main()

{

vector vec;

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 and using namespace std;

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!

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

Video Face Swap

Video Face Swap

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

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)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1253
29
C# Tutorial
1227
24
How to Fix the Steam Cloud Error? Try These Methods How to Fix the Steam Cloud Error? Try These Methods Apr 04, 2025 am 01:51 AM

The Steam Cloud error can be caused by many reasons. To play a game smoothly, you need to take some measures to remove this error before you launch the game. php.cn Software introduces some best ways as well as more useful information in this post.

Remove PC App Store Malware - A Full Guide for You! Remove PC App Store Malware - A Full Guide for You! Apr 04, 2025 am 01:41 AM

If you have a program called PC App Store on your computer and did not purposely install it, then your PC may be infected with the malware. This post from php.cn introduces how to remove PC App Store malware.

Fixdisk Windows 7: Check Your Hard Disk for Errors on Windows 7 Fixdisk Windows 7: Check Your Hard Disk for Errors on Windows 7 Apr 14, 2025 am 12:40 AM

If you suspect your hard drive encounters issues, you can check the drive for errors on Windows 7. This php.cn post talks about fixdisk Windows 7. You can follow the guide to check the hard drive for errors on Windows 7.

Is Core Isolation Blocked by ew_usbccgpfilter.sys? Here Are Fixes! Is Core Isolation Blocked by ew_usbccgpfilter.sys? Here Are Fixes! Apr 13, 2025 am 12:47 AM

Many SurfaceBook users report that they meet the “core isolation blocked by ew_usbccgpfilter.sys” issue on Windows 11/10. This post from php.cn helps to fix the annoying issue. Keep on your reading.

Effortles Fixes for Black Screen After Installing a Graphics Driver Effortles Fixes for Black Screen After Installing a Graphics Driver Apr 15, 2025 am 12:11 AM

Have you ever encountered a black screen after installing a graphics driver like an Nvidia driver in Windows 10/11? Now in this post from php.cn, you can find a couple of worth trying solutions to the Nvidia driver update black screen.

How to Install Windows X-Lite Optimum 11 23H2 Home/Pro via ISO How to Install Windows X-Lite Optimum 11 23H2 Home/Pro via ISO Apr 09, 2025 am 12:49 AM

Windows X-Lite Optimum 11 23H2 Home or Optimum 11 Pro could be your option if you need a custom lite system based on Windows 11 23H2. Go on reading and php.cn will show you how to download Optimum 11 23H2 ISO and install Pro or Home on your PC.

HackTool:Win64/ExplorerPatcher!MTB - How to Remove? HackTool:Win64/ExplorerPatcher!MTB - How to Remove? Apr 04, 2025 am 01:23 AM

ExplorerPatcher is an Open-Source portable executable that lets you customise the Windows 11 Start Menu, Taskbar, File Explorer, and more. However, many users receive this Trojan warning about HackTool:Win64/ExplorerPatcher!MTB. Why does that happen

Win 11 Builds 22621.3078 and 22631.3078 (KB5034204) Released Win 11 Builds 22621.3078 and 22631.3078 (KB5034204) Released Apr 05, 2025 am 01:35 AM

Want to know the new improvements and bug fixes in Windows 11 KB5034204? Want to how to get Windows 11 KB5034204 on your device? In this post, php.cn Software will introduce the information you want to know.

See all articles