Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between GetDesktopWindow() and HWND_DESKTOP

Tags:

winapi

There's a win32 api function, GetDesktopWindow(), which returns a handle of desktop window.

And there's another one - HWND_DESKTOP macro. I couldn't find official information in MSDN, but it's found in WinUser.h

#define HWND_DESKTOP        ((HWND)0)

So, what's difference between them?

like image 309
ikh Avatar asked Nov 02 '14 04:11

ikh


1 Answers

HWND_DESKTOP is only used by MapWindowRect() to indicate using screen coordinates, as documented on MSDN. You'll notice its value is equal to NULL, which is also listed there. I'm guessing HWND_DESKTOP came first.

Of course, valid windows cannot be NULL for real, so HWND_DESKTOP isn't the handle of the desktop window. While I don't know of any real good things you can do with it, the proper way to get the desktop window's handle is with that function.

(For what it's worth, the example for GetDesktopWindow() uses the returned handle to position a dialog box on screen. I don't know if the current preference is to use the current monitor's work area instead...)

like image 168
andlabs Avatar answered Sep 26 '22 20:09

andlabs