WPF将窗体设置为桌面背景【动态桌面】
时间:2020-05-13 11:18:55
收藏:0
阅读:290
#region MyRegion private IntPtr programIntPtr = IntPtr.Zero; bool inited { get; set; } public void Init() { try { if (inited) return; // 通过类名查找一个窗口,返回窗口句柄。 programIntPtr = Win32.FindWindow("Progman", null); // 窗口句柄有效 if (programIntPtr != IntPtr.Zero) { IntPtr result = IntPtr.Zero; // 向 Program Manager 窗口发送 0x52c 的一个消息,超时设置为0x3e8(1秒)。 Win32.SendMessageTimeout(programIntPtr, 0x52c, IntPtr.Zero, IntPtr.Zero, 0, 0x3e8, result); // 遍历顶级窗口 Win32.EnumWindows((hwnd, lParam) => { // 找到包含 SHELLDLL_DefView 这个窗口句柄的 WorkerW if (Win32.FindWindowEx(hwnd, IntPtr.Zero, "SHELLDLL_DefView", null) != IntPtr.Zero) { // 找到当前 WorkerW 窗口的,后一个 WorkerW 窗口。 IntPtr tempHwnd = Win32.FindWindowEx(IntPtr.Zero, hwnd, "WorkerW", null); // 隐藏这个窗口 Win32.ShowWindow(tempHwnd, 0); } return true; }, IntPtr.Zero); } Win32.SetParent(new System.Windows.Interop.WindowInteropHelper(this).Handle, programIntPtr); inited = true; } catch (Exception ex) { } } #endregion
原文:https://www.cnblogs.com/RedSky/p/12880887.html
评论(0)