From e4a0b3f39352485d3ed937eab41b41c974c2abb6 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sun, 1 Dec 2024 18:56:44 -0600 Subject: [PATCH] Handle cloak event --- .../NativeMethods.User32.cs | 1 + .../ApplicationWindow.cs | 7 ------ src/ManagedShell.WindowsTasks/TasksService.cs | 23 ++++++++++--------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/ManagedShell.Interop/NativeMethods.User32.cs b/src/ManagedShell.Interop/NativeMethods.User32.cs index e476dc48..12ea37e5 100644 --- a/src/ManagedShell.Interop/NativeMethods.User32.cs +++ b/src/ManagedShell.Interop/NativeMethods.User32.cs @@ -1916,6 +1916,7 @@ public enum TBPFLAG public static IntPtr HWND_BROADCAST = new IntPtr(0xffff); public static int WINEVENT_OUTOFCONTEXT = 0; public static int WINEVENT_SKIPOWNPROCESS = 2; + public static int EVENT_OBJECT_CLOAKED = 0x8017; public static int EVENT_OBJECT_UNCLOAKED = 0x8018; public static int EVENT_OBJECT_LOCATIONCHANGE = 0x800B; diff --git a/src/ManagedShell.WindowsTasks/ApplicationWindow.cs b/src/ManagedShell.WindowsTasks/ApplicationWindow.cs index 96fbfd26..4a5493cd 100644 --- a/src/ManagedShell.WindowsTasks/ApplicationWindow.cs +++ b/src/ManagedShell.WindowsTasks/ApplicationWindow.cs @@ -411,13 +411,6 @@ private string getFileDescription() return desc; } - internal void Uncloak() - { - ShellLogger.Debug($"ApplicationWindow: Uncloak event received for {Title}"); - - SetShowInTaskbar(); - } - private void setIcon() { if (!_iconLoading && ShowInTaskbar) diff --git a/src/ManagedShell.WindowsTasks/TasksService.cs b/src/ManagedShell.WindowsTasks/TasksService.cs index 550a0479..4b03152e 100644 --- a/src/ManagedShell.WindowsTasks/TasksService.cs +++ b/src/ManagedShell.WindowsTasks/TasksService.cs @@ -30,8 +30,8 @@ public class TasksService : DependencyObject, IDisposable private static int WM_SHELLHOOKMESSAGE = -1; private static int WM_TASKBARCREATEDMESSAGE = -1; private static int TASKBARBUTTONCREATEDMESSAGE = -1; - private static IntPtr uncloakEventHook = IntPtr.Zero; - private WinEventProc uncloakEventProc; + private static IntPtr cloakEventHook = IntPtr.Zero; + private WinEventProc cloakEventProc; private static IntPtr moveEventHook = IntPtr.Zero; private WinEventProc moveEventProc; @@ -103,16 +103,16 @@ internal void Initialize(bool withMultiMonTracking) if (EnvironmentHelper.IsWindows8OrBetter) { - // set event hook for uncloak events - uncloakEventProc = UncloakEventCallback; + // set event hook for cloak/uncloak events + cloakEventProc = CloakEventCallback; - if (uncloakEventHook == IntPtr.Zero) + if (cloakEventHook == IntPtr.Zero) { - uncloakEventHook = SetWinEventHook( - EVENT_OBJECT_UNCLOAKED, + cloakEventHook = SetWinEventHook( + EVENT_OBJECT_CLOAKED, EVENT_OBJECT_UNCLOAKED, IntPtr.Zero, - uncloakEventProc, + cloakEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS); @@ -197,7 +197,7 @@ public void Dispose() { ShellLogger.Debug("TasksService: Deregistering hooks"); DeregisterShellHookWindow(_HookWin.Handle); - if (uncloakEventHook != IntPtr.Zero) UnhookWinEvent(uncloakEventHook); + if (cloakEventHook != IntPtr.Zero) UnhookWinEvent(cloakEventHook); if (moveEventHook != IntPtr.Zero) UnhookWinEvent(moveEventHook); _HookWin.DestroyHandle(); setTaskbarListHwnd(IntPtr.Zero); @@ -618,14 +618,15 @@ private void MoveEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hWnd } } - private void UncloakEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hWnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) + private void CloakEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hWnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { if (hWnd != IntPtr.Zero && idObject == 0 && idChild == 0) { if (Windows.Any(i => i.Handle == hWnd)) { ApplicationWindow win = Windows.First(wnd => wnd.Handle == hWnd); - win.Uncloak(); + ShellLogger.Debug($"TasksService: {(eventType == EVENT_OBJECT_CLOAKED ? "Cloak" : "Uncloak")} event received for {win.Title}"); + win.SetShowInTaskbar(); } } }