From 8542719b53777eead35888e9e14877cb0981db94 Mon Sep 17 00:00:00 2001 From: Yukimono Date: Fri, 9 Jan 2015 21:26:45 +0530 Subject: [PATCH] Hide overlay in alt+tab --- OverlayPlugin/OverlayForm.cs | 2 ++ OverlayPlugin/Util.cs | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/OverlayPlugin/OverlayForm.cs b/OverlayPlugin/OverlayForm.cs index f1c02e21a..55c84bd77 100644 --- a/OverlayPlugin/OverlayForm.cs +++ b/OverlayPlugin/OverlayForm.cs @@ -67,6 +67,8 @@ public OverlayForm(string url, int maxFrameRate = 30) this.Renderer.Render += renderer_Render; this.url = url; + + Util.Hide(this); } public void Reload() diff --git a/OverlayPlugin/Util.cs b/OverlayPlugin/Util.cs index a50a61652..b2db4ad53 100644 --- a/OverlayPlugin/Util.cs +++ b/OverlayPlugin/Util.cs @@ -5,6 +5,8 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Diagnostics; +using System.Runtime.InteropServices; namespace RainbowMage.OverlayPlugin { @@ -37,5 +39,56 @@ public static bool IsOnScreen(Form form) return false; } + + [DllImport("user32.dll")] + public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex); + + [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)] + private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + + [DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)] + private static extern Int32 SetWindowLong(IntPtr hWnd, int nIndex, Int32 dwNewLong); + + [DllImport("kernel32.dll", EntryPoint = "SetLastError")] + public static extern void SetLastError(int dwErrorCode); + + private static int ptr32(IntPtr intPtr) + { + return unchecked((int)intPtr.ToInt64()); + } + + public static IntPtr SetWindowLongA(IntPtr hWnd, int nIndex, IntPtr dwNewLong) + { + int error = 0; + IntPtr result = IntPtr.Zero; + + SetLastError(0); + + if (IntPtr.Size == 4) + { + Int32 result32 = SetWindowLong(hWnd, nIndex, ptr32(dwNewLong)); + error = Marshal.GetLastWin32Error(); + result = new IntPtr(result32); + } + else + { + result = SetWindowLongPtr(hWnd, nIndex, dwNewLong); + error = Marshal.GetLastWin32Error(); + } + + if ((result == IntPtr.Zero) && (error != 0)) + { + throw new System.ComponentModel.Win32Exception(error); + } + + return result; + } + + public static void Hide(System.Windows.Forms.Form form) + { + int ex = (int)GetWindowLong(form.Handle, (int)(-20)); + ex |= (int)(0x00000080); + SetWindowLongA(form.Handle, (int)(-20), (IntPtr)ex); + } } }