From b35b379a9f14dd5b00d7df7b723f20c9fa452b13 Mon Sep 17 00:00:00 2001 From: RainbowMage Date: Sat, 17 Jan 2015 15:35:38 +0900 Subject: [PATCH] =?UTF-8?q?Pull=20request=20=E3=81=97=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=9F=E3=81=A0=E3=81=84=E3=81=9F=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=82=92=E6=95=B4=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OverlayPlugin.sln | 1 + OverlayPlugin/NativeMethods.cs | 46 ++++++++++++++++++++- OverlayPlugin/OverlayForm.cs | 3 +- OverlayPlugin/Properties/AssemblyInfo.cs | 2 +- OverlayPlugin/Util.cs | 52 ++---------------------- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/OverlayPlugin.sln b/OverlayPlugin.sln index 34261e070..61d3582d1 100644 --- a/OverlayPlugin.sln +++ b/OverlayPlugin.sln @@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{84CCF15D full.exclude = full.exclude LICENSE.txt = LICENSE.txt PS-Zip.psm1 = PS-Zip.psm1 + README-en.md = README-en.md README.md = README.md EndProjectSection EndProject diff --git a/OverlayPlugin/NativeMethods.cs b/OverlayPlugin/NativeMethods.cs index 64b22426c..da2536c9e 100644 --- a/OverlayPlugin/NativeMethods.cs +++ b/OverlayPlugin/NativeMethods.cs @@ -131,16 +131,58 @@ public static extern IntPtr CreateDIBSection( public const int DIB_RGB_COLORS = 0x0000; - [DllImport("user32.dll")] + [DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)] public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); - [DllImport("user32.dll")] + [DllImport("user32.dll", EntryPoint = "GetWindowLong", SetLastError = true)] public static extern int GetWindowLong(IntPtr hWnd, int nIndex); public const int GWL_EXSTYLE = -20; public const int WS_EX_TRANSPARENT = 0x00000020; + public const int WS_EX_TOOLWINDOW = 0x00000080; [DllImport("kernel32")] public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count); + + + // For hide from ALT+TAB preview + + [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)] + public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + + [DllImport("kernel32.dll", EntryPoint = "SetLastError")] + public static extern void SetLastError(int dwErrorCode); + + private static int ToIntPtr32(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, ToIntPtr32(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; + } } } diff --git a/OverlayPlugin/OverlayForm.cs b/OverlayPlugin/OverlayForm.cs index 55c84bd77..c1b9ce949 100644 --- a/OverlayPlugin/OverlayForm.cs +++ b/OverlayPlugin/OverlayForm.cs @@ -68,7 +68,8 @@ public OverlayForm(string url, int maxFrameRate = 30) this.url = url; - Util.Hide(this); + // Alt+Tab を押したときに表示されるプレビューから除外する + Util.HidePreview(this); } public void Reload() diff --git a/OverlayPlugin/Properties/AssemblyInfo.cs b/OverlayPlugin/Properties/AssemblyInfo.cs index 634670308..1d57ac789 100644 --- a/OverlayPlugin/Properties/AssemblyInfo.cs +++ b/OverlayPlugin/Properties/AssemblyInfo.cs @@ -32,4 +32,4 @@ // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を // 既定値にすることができます: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.3.1")] +[assembly: AssemblyVersion("0.2.4.0")] diff --git a/OverlayPlugin/Util.cs b/OverlayPlugin/Util.cs index b2db4ad53..f77428681 100644 --- a/OverlayPlugin/Util.cs +++ b/OverlayPlugin/Util.cs @@ -40,55 +40,11 @@ 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) + public static void HidePreview(System.Windows.Forms.Form form) { - int ex = (int)GetWindowLong(form.Handle, (int)(-20)); - ex |= (int)(0x00000080); - SetWindowLongA(form.Handle, (int)(-20), (IntPtr)ex); + int ex = NativeMethods.GetWindowLong(form.Handle, NativeMethods.GWL_EXSTYLE); + ex |= NativeMethods.WS_EX_TOOLWINDOW; + NativeMethods.SetWindowLongA(form.Handle, NativeMethods.GWL_EXSTYLE, (IntPtr)ex); } } }