public static void BeWallpaper(IntPtr form) { var progman = WinNative.FindWindow("Progman", null); WinNative.SendMessage(progman, 0x052C, 0x0000000D, 0); WinNative.SendMessage(progman, 0x052C, 0x0000000D, 1); WinNative.SendMessage(progman, 0x052C, 0x0000000D, 0); WinNative.SendMessage(progman, 0x052C, 0x0000000D, 1); IntPtr target = IntPtr.Zero; int count = 5; while (target == IntPtr.Zero) { WinNative.EnumWindows(new WinNative.EnumWindowsProc((hwnd, param) => { IntPtr p = WinNative.FindWindowEx(hwnd, IntPtr.Zero, "SHELLDLL_DefView", null); if (p != IntPtr.Zero) { target = WinNative.FindWindowEx(IntPtr.Zero, hwnd, "WorkerW", null); if (target != IntPtr.Zero) { return(false); } } return(true); }), IntPtr.Zero); if (--count <= 0) { throw new NotSupportedException(); } } WinNative.SetParent(form, target); WinNative.ShowWindow(form, WinNative.SW_MAXIMIZE); }
public static List <IntPtr> GetProcessMainWindows(int dwProcessID) { IntPtr hwnd = IntPtr.Zero; List <IntPtr> windows = new List <IntPtr>(); do { hwnd = WinNative.FindWindowEx(IntPtr.Zero, hwnd, null, null); uint dwPID = 0; WinNative.GetWindowThreadProcessId(hwnd, out dwPID); if (dwPID == dwProcessID) { windows.Add(hwnd); } }while (hwnd != IntPtr.Zero); return(windows); }