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
4
votes
3 answers

How to best encapsulate window handles?

I'm developing a system composed of many independent subsystems. Two of such subsystems are the Window and the GraphicsAdapter subsystem. The GraphicsAdapter requires a low-level window handle (HWND or X11 Window Handle, depending of the operating…
Gui Prá
  • 5,559
  • 4
  • 34
  • 59
4
votes
1 answer

I want to disable the shadow effect on a specific aero window

I want to disable the shadow effect on a specific aero window. All I have is the HWND of this window, is this possible?
Don
  • 85
  • 1
  • 5
4
votes
2 answers

Qt QML component like WPF HwndHost

We have a desktop windows application that uses a component that needs a HWND to be displayed. In a WPF application we use a HwndHost to display it. We are trying to make a Qt QML based application to do the same. Is it possible to host a HWND…
Stefano Piovesan
  • 1,185
  • 3
  • 19
  • 37
4
votes
1 answer

Detecting an Application Focus Change / Hooking something for HWND changes?

How could I detect when any application loses focus? Is there any system hooks to use? I want to pick up when ever a new application is in focus, or when one is lost. Even having the "current" HWND of the user would be good. I am using C#,…
Mike Curry
  • 229
  • 1
  • 5
  • 9
4
votes
2 answers

Is there a way to know when another hwnd has closed?

Is there a method for setting up a listener/watcher to know when an unrelated application window is closed? I can check to see if the window is still open, but that seems silly to continually do.
Meep
  • 254
  • 1
  • 15
4
votes
2 answers

Creating a Win32 Window app with English title bar, but the title bar becomes Chinese out of nowhere. How come?

HWND wndHandle; //global variable // code snipped WNDCLASSEX wcex; // code snipped wcex.lpszClassName = (LPCWSTR) "MyTitleName"; // code snipped wndHandle = CreateWindow( (LPCWSTR)"MyTitleName", //the window class to use …
Karl
  • 5,613
  • 13
  • 73
  • 107
4
votes
3 answers

Key logger wont record key strokes without console

I created a small basic key logger in C++. For some reason when I compile and run the program with the console displayed, it will record every key stroke I make in whatever program I am using such as a browser and store it in a text file. However…
RandomGuy
  • 419
  • 4
  • 14
4
votes
0 answers

How to get a desktop window image on a Unity3D-texture

Using dwmapi.dll it is possible to "project" a real-time image of a desktop window onto another windows hwnd (DwmRegisterThumbnail) as used by the activity bar previews of running apps in Windows. Now I want to project this image onto a texture in…
Andreas Zita
  • 7,232
  • 6
  • 54
  • 115
4
votes
1 answer

WPF Memory Leak on XP (CMilChannel, HWND)

My WPF application leaks memory at about 4kb/s. The memory usage in Task Manager climbs constantly until the application crashes with an "Out of Memory" exception. By doing my own research I have found that the problem is discussed here: Track down…
vanja.
  • 2,532
  • 3
  • 23
  • 39
4
votes
1 answer

WindowsFromDc return null

I need some help about the win32 api and especially WindowsFromDc. I have a application which hook a another application. This two application communicate by a NamedPipe. In the second application, I have hook the DrawTextExW function and I get a…
4
votes
4 answers

How to get tooltip text for a given HWND?

I'm looking for a way to get the tooltip control (if any) which is associated with a given HWND. The text of the tooltip control would be sufficient, too. The closest thing I found is the TTM_GETTEXT message, but it's meant to be sent to the tooltip…
Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
4
votes
1 answer

FindWindow() doesn't find my window [C++]

This is not a complex question. I'm having trouble finding the handle that belongs to iTunes. But although iTunes is running in the background, it keeps telling me it can't find the window. So I went on checking whether I miss typed the window name,…
Rob
  • 175
  • 3
  • 3
  • 12
3
votes
2 answers

Close callback or WM_CLOSE from a HWND reference

I'm calling the HtmlHelpA winapi method to display the .chm of my app. This method returns a HWND immediatelly, and the help window is shown as a separate window. Along with the window, I set a timer for this hwnd. My problem is that I need to know…
Rodrigo Rivera
  • 157
  • 1
  • 9
3
votes
2 answers

Can I pass a HWND in a COM method?

Is it possible to have a COM method which passes a HWND? With the following method in my object CoCreateInstance returns DISP_E_BADVARTYPE (0x80020008): STDMETHODIMP ShowDialog(HWND hWndParent); So far, I'm getting round this problem by passing an…
Mat
  • 82,161
  • 34
  • 89
  • 109
3
votes
3 answers

Wpf: Getting the containing HwndSource of a custom control

I'm writing a custom Wpf control and I need to grab a reference to the containing window's HwndSource at the earliest possible time. This would be 1) in the constructor of my control if possible or 2) at the point when the control is added to the…
anthony
  • 40,424
  • 5
  • 55
  • 128