From 1bfb545d33d0306784efc769b9abb8c93e638cdc Mon Sep 17 00:00:00 2001 From: campbeb Date: Sat, 15 Oct 2016 16:41:25 -0400 Subject: [PATCH] Hide background UWP apps from window capture options UWP apps that aren't shown are 'cloaked' --- ShareX.HelpersLib/Native/NativeEnums.cs | 3 +++ ShareX.HelpersLib/Native/NativeMethods.cs | 3 +++ ShareX.HelpersLib/Native/NativeMethods_Helpers.cs | 7 +++++++ ShareX.HelpersLib/Native/WindowInfo.cs | 4 +++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ShareX.HelpersLib/Native/NativeEnums.cs b/ShareX.HelpersLib/Native/NativeEnums.cs index 7b55f3251..365b1109b 100644 --- a/ShareX.HelpersLib/Native/NativeEnums.cs +++ b/ShareX.HelpersLib/Native/NativeEnums.cs @@ -207,6 +207,9 @@ public enum DwmWindowAttribute HasIconicBitmap, DisallowPeek, ExcludedFromPeek, + Cloak, + Cloaked, + FreezeRepresentation, Last } diff --git a/ShareX.HelpersLib/Native/NativeMethods.cs b/ShareX.HelpersLib/Native/NativeMethods.cs index efd9edb7e..6666ac21d 100644 --- a/ShareX.HelpersLib/Native/NativeMethods.cs +++ b/ShareX.HelpersLib/Native/NativeMethods.cs @@ -392,6 +392,9 @@ public static partial class NativeMethods [DllImport("dwmapi.dll")] public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out bool pvAttribute, int cbAttribute); + [DllImport("dwmapi.dll")] + public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out int pvAttribute, int cbAttribute); + [DllImport("dwmapi.dll")] public static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind); diff --git a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs index 779eff689..a2f1f996e 100644 --- a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs +++ b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs @@ -349,6 +349,13 @@ public static bool IsWindowMaximized(IntPtr handle) return wp.showCmd == WindowShowStyle.Maximize; } + public static bool IsWindowCloaked(IntPtr handle) + { + int cloaked; + int result = DwmGetWindowAttribute(handle, (int)DwmWindowAttribute.Cloaked, out cloaked, sizeof(int)); + return result == 0 && cloaked != 0; + } + public static IntPtr SetHook(int hookType, HookProc hookProc) { using (Process currentProcess = Process.GetCurrentProcess()) diff --git a/ShareX.HelpersLib/Native/WindowInfo.cs b/ShareX.HelpersLib/Native/WindowInfo.cs index 36d02742f..a13bf6879 100644 --- a/ShareX.HelpersLib/Native/WindowInfo.cs +++ b/ShareX.HelpersLib/Native/WindowInfo.cs @@ -54,7 +54,9 @@ public class WindowInfo public bool IsMinimized => NativeMethods.IsIconic(Handle); - public bool IsVisible => NativeMethods.IsWindowVisible(Handle); + public bool IsVisible => NativeMethods.IsWindowVisible(Handle) && !IsCloaked; + + public bool IsCloaked => NativeMethods.IsWindowCloaked(Handle); public bool IsActive => NativeMethods.GetForegroundWindow() == Handle;