public bool SendToBackground(IntPtr handler, int displayIndex = 0) { if (handler == IntPtr.Zero || Shown) { return(false); } var ok = User32Wrapper.GetWindowRect(handler, out RECT react); if (ok) { _originalRect = react; } Shown = true; _targeHandler = handler; if (_workerw == IntPtr.Zero) { _workerw = GetWorkerW(); } _parentHandler = User32Wrapper.GetParent(_targeHandler); if (_parentHandler == IntPtr.Zero) { _parentHandler = User32Wrapper.GetAncestor(_targeHandler, GetAncestorFlags.GetParent); } User32Wrapper.SetParent(_targeHandler, _workerw); FullScreen(_targeHandler, displayIndex); return(true); }
internal void ShowWallpaper(IntPtr wallpaperHandle) { IntPtr hostForm = IntPtr.Zero; WallpaperApi.UIInvoke(() => { try { Controls.Clear(); Opacity = 1; hostForm = Handle; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"ShowWallpaper ex:{ex}"); } }); //hostfrom下潜桌面 WallpaperHelper.GetInstance(_screenName).SendToBackground(hostForm); //壁纸parent改为hostform User32Wrapper.SetParent(wallpaperHandle, hostForm); //把壁纸全屏铺满 hostform WallpaperHelper.FullScreen(wallpaperHandle, hostForm); }
public void RestoreParent(bool refreshWallpaper = true) { if (!Shown) { return; } if (refreshWallpaper) { _desktopWallpaperAPI = RefreshWallpaper(_desktopWallpaperAPI); } if (_workerw == IntPtr.Zero) { _workerw = GetWorkerW(); } User32Wrapper.SetParent(_currentHandler, _parentHandler); if (_originalRect != null) { User32WrapperEx.SetWindowPosEx(_currentHandler, _originalRect.Value); } Shown = false; }
public void RestoreParent() { if (_parentHandler != null) { User32Wrapper.SetParent(_currentHandler, _parentHandler.Value); } _parentHandler = null; }
public bool SendToBackground(IntPtr handler) { //处理alt+tab可以看见本程序 //https://stackoverflow.com/questions/357076/best-way-to-hide-a-window-from-the-alt-tab-program-switcher int exStyle = User32Wrapper.GetWindowLong(handler, WindowLongFlags.GWL_EXSTYLE); exStyle |= (int)WindowStyles.WS_EX_TOOLWINDOW; User32Wrapper.SetWindowLong(handler, WindowLongFlags.GWL_EXSTYLE, exStyle); if (handler != _currentHandler) { //已经换了窗口,恢复上一个窗口 RestoreParent(); } if (handler == IntPtr.Zero) { return(false); } _ = User32Wrapper.GetWindowRect(handler, out _); //var ok = User32Wrapper.GetWindowRect(handler, out RECT react); //if (ok) // _originalRect = react; _currentHandler = handler; var workerw = GetWorkerW(); if (workerw == IntPtr.Zero) { //有时候突然又不行了,在来一次 User32Wrapper.SystemParametersInfo(User32Wrapper.SPI_SETCLIENTAREAANIMATION, 0, true, User32Wrapper.SPIF_UPDATEINIFILE | User32Wrapper.SPIF_SENDWININICHANGE); workerw = GetWorkerW(); } if (workerw == IntPtr.Zero) { return(false); } _parentHandler = User32Wrapper.GetParent(_currentHandler); //if (newParentHandler != _parentHandler) //{ // //parent没变时不重复调用,有时候会导致不可见 User32Wrapper.SetParent(_currentHandler, workerw); FullScreen(_currentHandler, _targetBounds, workerw); //_parentHandler = newParentHandler; //} //if (_parentHandler == IntPtr.Zero) // _parentHandler = User32Wrapper.GetAncestor(_currentHandler, GetAncestorFlags.GetParent); return(true); }
public void RestoreParent() { if (_parentHandler != null) { User32Wrapper.SetParent(_currentHandler, _parentHandler.Value); } _parentHandler = null; ////恢复原始大小 //if (_originalRect != null) // User32WrapperEx.SetWindowPosEx(_currentHandler, _originalRect.Value); }
public void RestoreParent() { if (_workerw == IntPtr.Zero) { _workerw = GetWorkerW(); } User32Wrapper.SetParent(_currentHandler, _parentHandler); //恢复原始大小 if (_originalRect != null) { User32WrapperEx.SetWindowPosEx(_currentHandler, _originalRect.Value); } }
/// <summary> /// 恢复WorkerW中的所有句柄到桌面 /// </summary> public static void RestoreAllHandles() { var desktop = User32Wrapper.GetDesktopWindow(); var workw = GetWorkerW(); var enumWindowResult = User32Wrapper.EnumChildWindows(workw, new EnumWindowsProc((tophandle, topparamhandle) => { var txt = User32Wrapper.GetWindowText(tophandle); if (!string.IsNullOrEmpty(txt)) { User32Wrapper.SetParent(tophandle, desktop); } return(true); }), IntPtr.Zero); RefreshWallpaper(null); }
public bool SendToBackground(IntPtr handler) { if (handler != _currentHandler) { //已经换了窗口,恢复上一个窗口 RestoreParent(); } if (handler == IntPtr.Zero) { return(false); } var ok = User32Wrapper.GetWindowRect(handler, out RECT react); if (ok) { _originalRect = react; } _currentHandler = handler; var workerw = GetWorkerW(); if (workerw == IntPtr.Zero) { //有时候突然又不行了,在来一次 User32Wrapper.SystemParametersInfo(User32Wrapper.SPI_SETCLIENTAREAANIMATION, 0, true, User32Wrapper.SPIF_UPDATEINIFILE | User32Wrapper.SPIF_SENDWININICHANGE); workerw = GetWorkerW(); } if (workerw == IntPtr.Zero) { return(false); } _parentHandler = User32Wrapper.GetParent(_currentHandler); FullScreen(_currentHandler, _targetBounds); User32Wrapper.SetParent(_currentHandler, workerw); //if (_parentHandler == IntPtr.Zero) // _parentHandler = User32Wrapper.GetAncestor(_currentHandler, GetAncestorFlags.GetParent); return(true); }
public bool SendToBackground(IntPtr handler) { if (Shown && handler != _currentHandler) { //已经换了窗口,恢复上一个窗口 RestoreParent(false); } if (handler == IntPtr.Zero || Shown) { return(false); } var ok = User32Wrapper.GetWindowRect(handler, out RECT react); if (ok) { _originalRect = react; } Shown = true; _currentHandler = handler; if (_workerw == IntPtr.Zero) { _workerw = GetWorkerW(); if (_workerw == IntPtr.Zero) { return(false); } } _parentHandler = User32Wrapper.GetParent(_currentHandler); if (_parentHandler == IntPtr.Zero) { _parentHandler = User32Wrapper.GetAncestor(_currentHandler, GetAncestorFlags.GetParent); } User32Wrapper.SetParent(_currentHandler, _workerw); FullScreen(_currentHandler, DisplayScreen); return(true); }
public static void Show(IntPtr handler) { _handler = handler; if (_handler == IntPtr.Zero || _showed) { return; } if (!_initlized) { bool isOk = Initlize(); if (!isOk) { return; } } _showed = true; User32Wrapper.SetParent(_handler, _workerw); DesktopWallpaperAPI.Enable(false); }
public static void Close(bool restoreParent = false) { if (!_showed) { return; } _showed = false; if (!_initlized) { Initlize(); } if (restoreParent) { var desktop = User32Wrapper.GetDesktopWindow(); User32Wrapper.SetParent(_handler, desktop); } DesktopWallpaperAPI.Enable(true); }