How to Get the Window Handle of the Desktop

Get handle to desktop / shell window

The thing changed a little bit since there are slideshows as wallpaper available in Windows 7.
You are right with WorkerW, but this works only with wallpaper is set to slideshow effect.

When there is set the wallpaper mode to slideshow, you have to search for a window of class WorkerW and check the children, whether there is a SHELLDLL_DefView.
If there is no slideshow, you can use the good old GetShellWindow().

I had the same problem some months ago and I wrote a function for getting the right window. Unfortunately I can't find it. But the following should work. Only the Win32 Imports are missing:

public enum DesktopWindow
{
ProgMan,
SHELLDLL_DefViewParent,
SHELLDLL_DefView,
SysListView32
}

public static IntPtr GetDesktopWindow(DesktopWindow desktopWindow)
{
IntPtr _ProgMan = GetShellWindow();
IntPtr _SHELLDLL_DefViewParent = _ProgMan;
IntPtr _SHELLDLL_DefView = FindWindowEx(_ProgMan, IntPtr.Zero, "SHELLDLL_DefView", null);
IntPtr _SysListView32 = FindWindowEx(_SHELLDLL_DefView, IntPtr.Zero, "SysListView32", "FolderView");

if (_SHELLDLL_DefView == IntPtr.Zero)
{
EnumWindows((hwnd, lParam) =>
{
if (GetClassName(hwnd) == "WorkerW")
{
IntPtr child = FindWindowEx(hwnd, IntPtr.Zero, "SHELLDLL_DefView", null);
if (child != IntPtr.Zero)
{
_SHELLDLL_DefViewParent = hwnd;
_SHELLDLL_DefView = child;
_SysListView32 = FindWindowEx(child, IntPtr.Zero, "SysListView32", "FolderView"); ;
return false;
}
}
return true;
}, IntPtr.Zero);
}

switch (desktopWindow)
{
case DesktopWindow.ProgMan:
return _ProgMan;
case DesktopWindow.SHELLDLL_DefViewParent:
return _SHELLDLL_DefViewParent;
case DesktopWindow.SHELLDLL_DefView:
return _SHELLDLL_DefView;
case DesktopWindow.SysListView32:
return _SysListView32;
default:
return IntPtr.Zero;
}
}

In your case you would call GetDesktopWindow(DesktopWindow.SHELLDLL_DefViewParent); to get the top-level window for checking whether it is the foreground window.

Enumerate all window handles on desktop

EnumWindows() is for that. You call it and provide a callback. It invokes the callback for every found window and passes a handle to that window.

You can then use the handle to query the window parameters and decide whether it is of interest for you or do some action with it.

How do I get the desktop window handle?

You can't. It isn't owned by your process, and there's no way to access windows which aren't yours under Mac OS X unless you're Dock.app or the WindowServer. (Dock.app has some special privileges, which can't be duplicated by other processes, and WindowServer is directly responsible for the windows so it can do whatever it wants.)

Current versions of the Finder create desktop icons by creating a full-screen, mostly-transparent window with a very low level. If you're just trying to draw stuff on top of the desktop, you can probably do something similar.

Flutter windows: get win32 window handle of flutter app

Yes:

  • In the current framework API you can get the handle of the Flutter view (which isn't the top-level window) from the framework using GetNativeWindow(). If you want the top-level window, you can walk up from there using standard Win32 APIs.

  • Assuming you are using the FDE Windows runner, you can also get the top-level window directly in main.cpp using GetHandle().

How can I determine if, given a window handle, the window handle is part of the Windows UI as opposed to an application?

After some digging, I found this question which references the "GetDesktopWindow()" and "GetShellWindow()" pinvoke functions. Using the GetShellWindow() api and it's pid, I was able to determine the process ID of the windows shell, and compare it to the process ID of the application I was currently moving. Finally, since file explorer windows are part of the explorer process, I checked to see if the window has "File Explorer" as it's title, or if any of it's parent windows do.

[DllImport("user32.dll", SetLastError = false)]
private static extern IntPtr GetShellWindow();

[DllImport("user32.dll", SetLastError = true)]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out IntPtr lpdwProcessId);

public bool IsPartOfWindowsUI
{
get
{
var desktopwindow = new WindowRef(GetShellWindow());
return (desktopwindow.ThreadProcessID == ThreadProcessID &&
//Check to see if title of this window or it's parents are
//Basic file explorer windows
!TitleTree.Contains("File Explorer"));
}
}

How i can get window handle of running programs in windows

you are looking for:

Enumerating processes:

BOOL WINAPI EnumProcesses

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682623(v=vs.85).aspx

an example how to use is in same link

Enumerating windows

BOOL WINAPI EnumWindows

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497(v=vs.85).aspx

an example how to use it:
How to stop EnumWindows running infinitely win32



Related Topics



Leave a reply



Submit