public void ReleaseBackground(IntPtr dest) { if (dest != IntPtr.Zero) { DWMApi.DwmUnregisterThumbnail(dest); } }
public void BackgroundUpdate(IntPtr dest, int width, int height) { if (dest == IntPtr.Zero) { return; } DWMApi.DwmQueryThumbnailSourceSize(dest, out PSIZE size); var props = new DWM_THUMBNAIL_PROPERTIES { fVisible = true, dwFlags = DWMApi.DWM_TNP_VISIBLE | DWMApi.DWM_TNP_RECTDESTINATION | DWMApi.DWM_TNP_OPACITY, opacity = 255, rcDestination = new RECT(0, 0, width, height), }; if (size.x < width) { props.rcDestination.Right = props.rcDestination.Left + size.x; } if (size.y < height) { props.rcDestination.Bottom = props.rcDestination.Top + size.y; } DWMApi.DwmUpdateThumbnailProperties(dest, ref props); }
/// <summary> /// 设置缩略图到指定窗口句柄 /// </summary> public IntPtr SetDesktopBackgroundToWindow(IntPtr dest, int width, int height) { //backgroundPath = null; //IntPtr wep = IntPtr.Zero; //User32Window.EnumWindows(((hwnd, e) => //{ // IntPtr p = User32Window.FindWindowEx(hwnd, // IntPtr.Zero, // "SHELLDLL_DefView", // null); // if (p != IntPtr.Zero) // { // IntPtr workerw = User32Window.FindWindowEx(IntPtr.Zero, // hwnd, // "WorkerW", // null); // User32Window.EnumChildWindows(workerw, ((hwnd2, e2) => // { // wep = hwnd2; // return true; // }), IntPtr.Zero); // } // return true; //}), IntPtr.Zero); //if (wep == IntPtr.Zero) //{ // IntPtr r = IntPtr.Zero; // MouseHook.SystemParametersInfo((uint)MouseHook.SystemParametersDesktopInfo.SPI_GETDESKWALLPAPER, 300, r, (uint)MouseHook.SystemParamtersInfoFlags.None); // backgroundPath = Marshal.PtrToStringAuto(r); //默认桌面路径 // return; //} //User32Window.SetWindowPos(dest, HWND_BOTTOM, 0, 0, 0, 0, // SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_SHOWWINDOW); IntPtr p = User32Window.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", null); ReleaseBackground(dest); var temp = DWMApi.DwmRegisterThumbnail(dest, p, out dest); if (temp == 0) { BackgroundUpdate(dest, width, height); } return(dest); }
private void PropertyForm_Shown(object sender, EventArgs e) { AssemblyPage.Instance().SetVersionTypeU(MainForm.Instance.Version, MainForm.Instance.VersionType); _oldLanguage = RConfig.Instance.Language; if (SystemInfo.Instance.isGlassEnable) { DWMApi.DwmExtendFrameIntoClientArea(Handle, _margins); /* DWMApi.WTA_OPTIONS ops = new DWMApi.WTA_OPTIONS * { * Flags = DWMApi.WTNCA_NODRAWCAPTION | DWMApi.WTNCA_NODRAWICON, * Mask = DWMApi.WTNCA_NODRAWCAPTION | DWMApi.WTNCA_NODRAWICON * }; * * DWMApi.SetWindowThemeAttribute(Handle, * DWMApi.WindowThemeAttributeType.WTA_NONCLIENT, * ref ops, * (uint)Marshal.SizeOf(typeof(DWMApi.WTA_OPTIONS)));*/ } }