search
HomeComputer TutorialsComputer KnowledgeWhat does a screen window handle mean?

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
This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004)How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004)Mar 11, 2025 am 11:26 AM

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

How do I edit the Registry? (Warning: Use with caution!)How do I edit the Registry? (Warning: Use with caution!)Mar 21, 2025 pm 07:46 PM

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.

How do I manage services in Windows?How do I manage services in Windows?Mar 21, 2025 pm 07:52 PM

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

Discover How to Fix Drive Health Warning in Windows SettingsDiscover How to Fix Drive Health Warning in Windows SettingsMar 19, 2025 am 11:10 AM

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.

which application uses ene.syswhich application uses ene.sysMar 12, 2025 pm 01:25 PM

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

why won't driver asio.sys loadwhy won't driver asio.sys loadMar 10, 2025 pm 07:58 PM

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

How do I change the default app for a file type?How do I change the default app for a file type?Mar 21, 2025 pm 07:48 PM

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

How do I use the Group Policy Editor (gpedit.msc)?How do I use the Group Policy Editor (gpedit.msc)?Mar 21, 2025 pm 07:48 PM

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

See all articles

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools