Questions tagged [hwnd]

The Microsoft Windows operating environment identifies each form in an application by assigning it a handle, or hWnd. The hWnd property is used with Windows API calls. Many Windows operating environment functions require the hWnd of the active window as an argument.

In computer programming, a handle is an abstract reference to a resource. Handles are used when application software references blocks of memory or objects managed by another system, such as a database or an operating system.

While a pointer literally contains the address of the item to which it refers, a handle is an abstraction of a reference which is managed externally; its opacity allows the referent to be relocated in memory by the system without invalidating the handle, which is impossible with pointers. The extra layer of indirection also increases the control the managing system has over operations performed on the referent. Typically the handle is an index or a pointer into a global array of tombstones.

Handles were a popular solution to memory management in operating systems of the 1980s, such as Mac OS and Windows. Unix file descriptors are essentially handles. Like other desktop environments, the Windows API heavily uses handles to represent objects in the system and to provide a communication pathway between the operating system and user space. For example, a window on the desktop is represented by a handle of type HWND (handle, window).

Doubly indirect handles have fallen out of favour in recent times, as increases in available memory and improved virtual memory algorithms have made the use of the simpler pointer more attractive. However, many operating systems still apply the term to pointers to opaque, "private" data structures—opaque pointers—or to indexes into internal arrays passed from one process to its client.

A handle leak is a type of software bug that occurs when a computer program asks for a handle to a resource but does not free the handle when it is no longer used.

Wikipedia Article

397 questions
11
votes
5 answers

Changing HWND Window Procedure in runtime

I'm working in an IDE which creates a hwnd and its respective WndProc LRESULT CALLBACK. I need to change the WndProc to a custom one. I've read that SetWindowLong would do the job, but I can't find any working example. For example: HWND hwnd; //My…
ProtectedVoid
  • 1,293
  • 3
  • 17
  • 42
11
votes
5 answers

How do I GetModuleFileName() if I only have a window handle (hWnd)?

I'm trying to get the name of the executable of a window that is outside my C# 2.0 application. My app currently gets a window handle (hWnd) using the GetForegroundWindow() call from "user32.dll". From the digging that I've been able to do, I think…
Pretzel
  • 8,141
  • 16
  • 59
  • 84
11
votes
4 answers

Get HWND of each Window?

I am developing a python application and I want to get the HWND of each open windows. I need the name of the windows and the HWND to filter the list to manage some specifics windows, moving and resizing them. I have tried to do it myself looking…
user1618465
  • 1,813
  • 2
  • 32
  • 58
8
votes
2 answers

How to find the HWND that is preventing shutdown?

Somewhere in my application (along with 3rd party libraries of code) is a window procedure that is preventing Windows from: logging off shutting down restarting I found one spot in my code where I made the extraordinarily common mistake of calling…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
8
votes
1 answer

Passing Input events from HwndHost to underlying WPF controls?

is there a way to pass input events (primarily mouse, but eventually keyboard input too) that occurs on a HwndHost back to the underlying WPF controls (e.g. a panel) ? i can hook up to WndProc within the HwndHost and recveive the windows messages.…
Joachim Kerschbaumer
  • 9,695
  • 7
  • 49
  • 84
8
votes
3 answers

How do I clear a Direct2D render target to fully transparent

I'm trying to draw semi-transparent rectangles on an invisible HWND. However, clearing the window with ID2D1HwndRenderTarget::Clear just makes the entire window black, so when I draw rectangles on top, they look semi-black. If I don't Clear() and…
Saul
  • 992
  • 1
  • 13
  • 26
7
votes
1 answer

How do I view information about a HWND within visual studio while debugging?

Are there any well known tools or plugins I can use to get properties about HWNDs while debugging / stepping through Visual Studio? I know I can use Spy++ for these things, but it's cumbersome to do so while also stepping in the debugger. What I'd…
Armentage
  • 12,065
  • 8
  • 33
  • 33
7
votes
3 answers

long to HWND (VS8 C++)

How can I cast long to HWND (C++ visual studio 8)? Long lWindowHandler; HWND oHwnd = (HWND)lWindowHandler; But I got the following warning: warning C4312: 'type cast' : conversion from 'LONG' to 'HWND' of greater size Thanks.
Abc Stuff
7
votes
1 answer

How to retrieve the window handle of the current WinUI 3 MainWindow from a page in a frame in a NavigationView control on the MainWindow

I am creating my first WinUI 3 desktop application. I have a NavigationView on my MainWindow. I have 9 different pages that I navigate to via the frame in the NavigationView. One of the pages is for printing reports. I need to get the FileSavePicker…
LennyL
  • 225
  • 3
  • 9
7
votes
2 answers

Program to discover HWND of objects like windows and buttons

I remember a few years back, I used a program that was capable of showing properties and HWND of any object such as windows and buttons in any Windows program. As I remember it, you just held the mouse over the object of interest and the program…
inquam
  • 12,664
  • 15
  • 61
  • 101
7
votes
3 answers

Getting HWND off of CoreWindow object in UWP

This short MSDN documentation says CoreWindow has ICoreWindowInterop that obtains the handle HWND to the CoreWindow. But I cannot find references on how to get it (C#). Help, please. https://msdn.microsoft.com/en-us/library/dn302119(v=vs.85).aspx
gt6707a
  • 649
  • 1
  • 7
  • 12
7
votes
4 answers

Display an Adorner over a WebBrowser control

I'm using the System.Windows.Controls.WebBrowser for various things in my app and I've noticed that adorners are cut off when they are supposed to appear over a WebBrowser. I realize that the WebBrowser control is really a wrapper around a COM…
Anderson Imes
  • 25,500
  • 4
  • 67
  • 82
6
votes
1 answer

Enum HWND properties c++

I am trying to get properties from an HWND. I'm used information from Using Window Properties, but the example below is not working for me. I'm getting an error while compiling my code. argument of type "BOOL (__stdcall *)(HWND hwndSubclass,…
Illia Moroz
  • 343
  • 1
  • 2
  • 13
6
votes
1 answer

How can I scan and transfer images from a document feeder asynchronously

Which parts of the communication with TWAIN can be put into another thread, e.g. a BackgroundWorker? Or: Is it possible to split the loop that handles the image transfer? Some scanner drivers scan all images before returning to the calling…
matthias.lukaszek
  • 2,200
  • 1
  • 23
  • 33
6
votes
3 answers

Get hWnd of the current window/form in VB6?

Ho do I get hWnd of the current window/form in VB6?
C. Ross
  • 31,137
  • 42
  • 147
  • 238
1
2
3
26 27