public static bool Show(IRender render, Screen screen) { var handle = render.ShowRender(); var core = GetCore(screen); if (core == null) { return(false); } Close(core.Render);//清理旧Render render.SetCore(core); core.Render = render; //处理alt+tab可以看见本程序 //https://stackoverflow.com/questions/357076/best-way-to-hide-a-window-from-the-alt-tab-program-switcher int exStyle = User32Wrapper.GetWindowLong(handle, WindowLongFlags.GWL_EXSTYLE); exStyle |= (int)WindowStyles.WS_EX_TOOLWINDOW; User32Wrapper.SetWindowLong(handle, WindowLongFlags.GWL_EXSTYLE, exStyle); bool ok = core.SendToBackground(handle); return(ok); }
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 static void FullScreen(IntPtr targeHandler, RECT rect, IntPtr parent) { User32Wrapper.MapWindowPoints(IntPtr.Zero, parent, ref rect, 2); _ = User32WrapperEx.SetWindowPosEx(targeHandler, rect); var style = User32Wrapper.GetWindowLong(targeHandler, WindowLongFlags.GWL_STYLE); //https://stackoverflow.com/questions/2398746/removing-window-border //消除游戏边框 style &= ~(int)(WindowStyles.WS_EX_TOOLWINDOW | WindowStyles.WS_CAPTION | WindowStyles.WS_THICKFRAME | WindowStyles.WS_MINIMIZEBOX | WindowStyles.WS_MAXIMIZEBOX | WindowStyles.WS_SYSMENU); User32Wrapper.SetWindowLong(targeHandler, WindowLongFlags.GWL_STYLE, style); }