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 {