From e41caba22022fb83692de5a2209585cb696c4f94 Mon Sep 17 00:00:00 2001 From: Kang Yu Date: Sat, 26 Apr 2025 22:29:16 -0700 Subject: [PATCH] improve debug message --- .../Common/PersistentWindowProcessor.cs | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs b/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs index 1514345..7187d05 100644 --- a/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs +++ b/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs @@ -1858,6 +1858,9 @@ namespace PersistentWindows.Common if (!initialized) return; + if (hwnd == IntPtr.Zero) + return; + { switch (eventType) { @@ -2674,22 +2677,6 @@ namespace PersistentWindows.Common ApplicationDisplayMetrics prevDisplayMetrics; if (IsWindowMoved(displayKey, hWnd, eventType, now, out curDisplayMetrics, out prevDisplayMetrics)) { - if (debugWindows.Contains(hWnd)) - { - string log = string.Format("Captured {0,-8} at {1} '{2}' fullscreen:{3} minimized:{4}", - curDisplayMetrics, - curDisplayMetrics.ScreenPosition.ToString(), - curDisplayMetrics.Title, - curDisplayMetrics.IsFullScreen, - curDisplayMetrics.IsMinimized - ); - Log.Event(log); - - string log2 = string.Format(" WindowPlacement.NormalPosition at {0}", - curDisplayMetrics.WindowPlacement.NormalPosition.ToString()); - Log.Event(log2); - } - bool new_window = !monitorApplications[displayKey].ContainsKey(hWnd); if (eventType != 0 || new_window) curDisplayMetrics.IsValid = true; @@ -2714,6 +2701,24 @@ namespace PersistentWindows.Common TrimQueue(displayKey, hWnd); } + if (debugWindows.Contains(hWnd)) + { + string log = string.Format("Captured {0} '{1}' fullscreen:{2} minimized:{3} visible:{4} at {5} {6, -8}", + curDisplayMetrics.HWnd.ToString("X"), + curDisplayMetrics.Title, + curDisplayMetrics.IsFullScreen, + curDisplayMetrics.IsMinimized, + !curDisplayMetrics.IsInvisible, + curDisplayMetrics.ScreenPosition.ToString(), + curDisplayMetrics + ); + Log.Event(log); + + string log2 = string.Format(" WindowPlacement.NormalPosition at {0}", + curDisplayMetrics.WindowPlacement.NormalPosition.ToString()); + Log.Event(log2); + } + monitorApplications[displayKey][hWnd].Add(curDisplayMetrics); ret = true; } @@ -3140,13 +3145,13 @@ namespace PersistentWindows.Common if (hwnd != kid) { if (prevDisplayMetrics.Title != curDisplayMetrics.Title) - Log.Error($"Inherit position data from killed window {prevDisplayMetrics.Title} with different title {curDisplayMetrics.Title} {prevDisplayMetrics.HWnd.ToString("X")}"); + Log.Error($"{hwnd.ToString("X")} Inherit position data from killed window {prevDisplayMetrics.Title} with different title {curDisplayMetrics.Title} {prevDisplayMetrics.HWnd.ToString("X")}"); else - Log.Error($"Inherit position data from killed window {prevDisplayMetrics.Title} {prevDisplayMetrics.HWnd.ToString("X")}"); + Log.Error($"{hwnd.ToString("X")} Inherit position data from killed window {prevDisplayMetrics.Title} {prevDisplayMetrics.HWnd.ToString("X")}"); ResolveWindowHandleCollision(hwnd); } else - Log.Error($"Inherit position data from existing window 0x{kid.ToString("X")} for {curDisplayMetrics.Title}"); + Log.Error($"{hwnd.ToString("X")} Inherit position data from existing window 0x{kid.ToString("X")} for {curDisplayMetrics.Title}"); if (initialized && autoRestoreNewWindowToLastCapture) return true;