From 740a3c5b90bef0cf92ef0352c7a7ec300ebd7b7a Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 10 Jun 2026 23:19:55 -0500 Subject: [PATCH] Restore preview card on system wake pc went to sleep, hover preview was missing (minimized?) this workaround works, maybe I can deduplicate the dllimport in PokePreview, or make this more abstract for future hover card previews like encounters? --- PKHeX.WinForms/Controls/Slots/PokePreview.cs | 1 - .../Controls/Slots/SummaryPreviewer.cs | 24 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/PKHeX.WinForms/Controls/Slots/PokePreview.cs b/PKHeX.WinForms/Controls/Slots/PokePreview.cs index a8062b631..068ebe870 100644 --- a/PKHeX.WinForms/Controls/Slots/PokePreview.cs +++ b/PKHeX.WinForms/Controls/Slots/PokePreview.cs @@ -467,7 +467,6 @@ public void MoveForm(int x, int y) const uint SWP_ASYNCWINDOWPOS = 0x4000; const uint flags = SWP_NOZORDER | SWP_NOSIZE | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_ASYNCWINDOWPOS; - const int HWND_TOPMOST = -1; SetWindowPos(Handle, HWND_TOPMOST, x, y, 0, 0, flags); return; diff --git a/PKHeX.WinForms/Controls/Slots/SummaryPreviewer.cs b/PKHeX.WinForms/Controls/Slots/SummaryPreviewer.cs index d785f8806..7be89bd10 100644 --- a/PKHeX.WinForms/Controls/Slots/SummaryPreviewer.cs +++ b/PKHeX.WinForms/Controls/Slots/SummaryPreviewer.cs @@ -70,12 +70,32 @@ private static void SetWindowState(Form frm, bool visible) { try { + if (!frm.IsHandleCreated || frm.IsDisposed) + return; + const int SW_SHOWNOACTIVATE = 4; - var state = visible ? SW_SHOWNOACTIVATE : 0; - ShowWindowAsync(frm.Handle, state); + const int HWND_TOPMOST = -1; + const uint SWP_NOMOVE = 0x0002; + const uint SWP_NOSIZE = 0x0001; + const uint SWP_NOACTIVATE = 0x0010; + const uint SWP_SHOWWINDOW = 0x0040; + const uint SWP_NOOWNERZORDER = 0x0200; + + if (visible) + { + ShowWindowAsync(frm.Handle, SW_SHOWNOACTIVATE); + SetWindowPos(frm.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER); + } + else + { + ShowWindowAsync(frm.Handle, 0); + } [System.Runtime.InteropServices.DllImport("user32.dll")] static extern bool ShowWindowAsync(nint hWnd, int nCmdShow); + + [System.Runtime.InteropServices.DllImport("user32.dll")] + static extern bool SetWindowPos(nint hWnd, nint hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags); } catch {