diff --git a/OneMore/Helpers/Extensions/FormExtensions.cs b/OneMore/Helpers/Extensions/FormExtensions.cs deleted file mode 100644 index a02e8e0fd8..0000000000 --- a/OneMore/Helpers/Extensions/FormExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ - - -namespace River.OneMoreAddIn -{ - using System; - using System.Runtime.InteropServices; - using System.Windows.Forms; - - - internal static class FormExtensions - { - private static readonly IntPtr HWND_TOPMOST = new(-1); - - private const uint SWP_NOSIZE = 0x0001; - private const uint SWP_NOMOVE = 0x0002; - - [DllImport("user32.dll")] - static extern bool SetWindowPos (IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); - - - public static void ForceTopMost (this Form form) - { - SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); - } - } -} diff --git a/OneMore/Helpers/Native.cs b/OneMore/Helpers/Native.cs index 2d09d9515f..6312d7c520 100644 --- a/OneMore/Helpers/Native.cs +++ b/OneMore/Helpers/Native.cs @@ -1,5 +1,5 @@ //************************************************************************************************ -// Copyright © 2020 Steven M Cohn. All rights reserved. +// Copyright © 2020 Steven M Cohn. All rights reserved. //************************************************************************************************ namespace River.OneMoreAddIn @@ -56,6 +56,9 @@ internal static class Native public const int IDC_HAND = 32649; public const int IDC_SIZENS = 32645; + public const uint SWP_NOSIZE = 0x0001; + public const uint SWP_NOMOVE = 0x0002; + public const int TVIF_STATE = 0x8; public const int TVIS_STATEIMAGEMASK = 0xF000; @@ -318,6 +321,7 @@ public static extern bool InsertMenu( IntPtr hMenu, int wPosition, int wFlags, int wIDNewItem, string lpNewItem); + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-releasecapture [DllImport("user32.dll")] public static extern bool ReleaseCapture(); @@ -359,6 +363,12 @@ public static extern bool InsertMenu( public static extern bool SetProcessDPIAware(); + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos + [DllImport("user32.dll")] + public static extern bool SetWindowPos( + IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); + + // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwineventhook [DllImport("user32.dll")] public static extern IntPtr SetWinEventHook( diff --git a/OneMore/OneMore.csproj b/OneMore/OneMore.csproj index 5bc400f198..c234665283 100644 --- a/OneMore/OneMore.csproj +++ b/OneMore/OneMore.csproj @@ -1011,7 +1011,6 @@ - diff --git a/OneMore/UI/MoreForm.cs b/OneMore/UI/MoreForm.cs index 2f63f19db0..0f412c4295 100644 --- a/OneMore/UI/MoreForm.cs +++ b/OneMore/UI/MoreForm.cs @@ -214,7 +214,11 @@ private void SetForegroundWindow(Form form) Native.SetForegroundWindow(form.Handle); form.BringToFront(); + + // this is the trick needed to elevate a dialog to TopMost + form.TopMost = false; form.TopMost = true; + form.Activate(); form.TopMost = false; @@ -223,6 +227,14 @@ private void SetForegroundWindow(Form form) } + public void ForceTopMost() + { + IntPtr HWND_TOPMOST = new(-1); + Native.SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, + Native.SWP_NOMOVE | Native.SWP_NOSIZE); + } + + public virtual void OnThemeChange() { } diff --git a/OneMore/UI/WindowElevator.cs b/OneMore/UI/WindowElevator.cs index 9ca3bd99c9..2594b2fb03 100644 --- a/OneMore/UI/WindowElevator.cs +++ b/OneMore/UI/WindowElevator.cs @@ -1,4 +1,8 @@ -namespace River.OneMoreAddIn.UI +//************************************************************************************************ +// Copyright © 2017 Steven M Cohn. All rights reserved. +//************************************************************************************************ + +namespace River.OneMoreAddIn.UI { using System.Windows.Forms;