Skip to content

Commit

Permalink
topmost
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Feb 10, 2024
1 parent 07ee49a commit 1833af0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
26 changes: 0 additions & 26 deletions OneMore/Helpers/Extensions/FormExtensions.cs

This file was deleted.

12 changes: 11 additions & 1 deletion OneMore/Helpers/Native.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//************************************************************************************************
// Copyright © 2020 Steven M Cohn. All rights reserved.
// Copyright © 2020 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion OneMore/OneMore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,6 @@
</Compile>
<Compile Include="Helpers\Extensions\ExceptionExtensions.cs" />
<Compile Include="Helpers\Extensions\BitmapExtensions.cs" />
<Compile Include="Helpers\Extensions\FormExtensions.cs" />
<Compile Include="Helpers\Extensions\StringExtensions.cs" />
<Compile Include="Commands\Tools\ShowXmlCommand.cs" />
<Compile Include="Models\TableProperties.cs" />
Expand Down
12 changes: 12 additions & 0 deletions OneMore/UI/MoreForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
{
}
Expand Down
6 changes: 5 additions & 1 deletion OneMore/UI/WindowElevator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace River.OneMoreAddIn.UI
//************************************************************************************************
// Copyright © 2017 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.UI
{
using System.Windows.Forms;

Expand Down

0 comments on commit 1833af0

Please sign in to comment.