diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index f2b9421..cfd4ed9 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -2,7 +2,8 @@ using System.Windows; using System.Windows.Threading; -using Microsoft.Win32; +using Windows.Win32; +using Windows.Win32.Foundation; namespace Bloxstrap { @@ -215,9 +216,9 @@ namespace Bloxstrap if (menuProcess is not null) { - IntPtr handle = menuProcess.MainWindowHandle; + var handle = menuProcess.MainWindowHandle; Logger.WriteLine(LOG_IDENT, $"Found an already existing menu window with handle {handle}"); - NativeMethods.SetForegroundWindow(handle); + PInvoke.SetForegroundWindow((HWND)handle); } else { diff --git a/Bloxstrap/Bloxstrap.csproj b/Bloxstrap/Bloxstrap.csproj index 8a14469..2257c75 100644 --- a/Bloxstrap/Bloxstrap.csproj +++ b/Bloxstrap/Bloxstrap.csproj @@ -40,6 +40,10 @@ + + + all + diff --git a/Bloxstrap/NativeMethods.txt b/Bloxstrap/NativeMethods.txt new file mode 100644 index 0000000..a66c6fa --- /dev/null +++ b/Bloxstrap/NativeMethods.txt @@ -0,0 +1,4 @@ +SetForegroundWindow +FlashWindow +GetWindowLong +SetWindowLong diff --git a/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs b/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs index c07d37f..d2f6a8a 100644 --- a/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs +++ b/Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs @@ -1,17 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; using System.Windows.Interop; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; + +using Windows.Win32; +using Windows.Win32.Foundation; +using Windows.Win32.UI.WindowsAndMessaging; using Bloxstrap.Integrations; @@ -92,10 +85,11 @@ namespace Bloxstrap.UI.Elements.ContextMenu // this is done to register the context menu wrapper as a tool window so it doesnt appear in the alt+tab switcher // https://stackoverflow.com/a/551847/11852173 - var wndHelper = new WindowInteropHelper(this); - long exStyle = NativeMethods.GetWindowLongPtr(wndHelper.Handle, NativeMethods.GWL_EXSTYLE).ToInt64(); - exStyle |= NativeMethods.WS_EX_TOOLWINDOW; - NativeMethods.SetWindowLongPtr(wndHelper.Handle, NativeMethods.GWL_EXSTYLE, (IntPtr)exStyle); + HWND hWnd = (HWND)new WindowInteropHelper(this).Handle; + + int exStyle = PInvoke.GetWindowLong(hWnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); + exStyle |= 0x00000080; //NativeMethods.WS_EX_TOOLWINDOW; + PInvoke.SetWindowLong(hWnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, exStyle); } private void Window_Closed(object sender, EventArgs e) => App.Logger.WriteLine("MenuContainer::Window_Closed", "Context menu container closed"); diff --git a/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml.cs b/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml.cs index 806a91f..b34a905 100644 --- a/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml.cs +++ b/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml.cs @@ -1,6 +1,9 @@ using System.Media; using System.Windows.Interop; +using Windows.Win32; +using Windows.Win32.Foundation; + namespace Bloxstrap.UI.Elements.Dialogs { // hmm... do i use MVVM for this? @@ -34,8 +37,8 @@ namespace Bloxstrap.UI.Elements.Dialogs Loaded += delegate { - IntPtr hWnd = new WindowInteropHelper(this).Handle; - NativeMethods.FlashWindow(hWnd, true); + var hWnd = new WindowInteropHelper(this).Handle; + PInvoke.FlashWindow((HWND)hWnd, true); }; } } diff --git a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs index 84bc721..e53485d 100644 --- a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs +++ b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs @@ -2,6 +2,9 @@ using System.Windows; using System.Windows.Interop; +using Windows.Win32; +using Windows.Win32.Foundation; + namespace Bloxstrap.UI.Elements.Dialogs { // hmm... do i use MVVM for this? @@ -60,7 +63,7 @@ namespace Bloxstrap.UI.Elements.Dialogs Loaded += delegate { IntPtr hWnd = new WindowInteropHelper(this).Handle; - NativeMethods.FlashWindow(hWnd, true); + PInvoke.FlashWindow((HWND)hWnd, true); }; } } diff --git a/Bloxstrap/UI/Elements/Dialogs/FluentMessageBox.xaml.cs b/Bloxstrap/UI/Elements/Dialogs/FluentMessageBox.xaml.cs index 958d351..6993406 100644 --- a/Bloxstrap/UI/Elements/Dialogs/FluentMessageBox.xaml.cs +++ b/Bloxstrap/UI/Elements/Dialogs/FluentMessageBox.xaml.cs @@ -4,6 +4,9 @@ using System.Windows.Controls; using System.Windows.Interop; using System.Windows.Media.Imaging; +using Windows.Win32; +using Windows.Win32.Foundation; + using Bloxstrap.UI.Utility; namespace Bloxstrap.UI.Elements.Dialogs @@ -107,8 +110,8 @@ namespace Bloxstrap.UI.Elements.Dialogs Loaded += delegate { - IntPtr hWnd = new WindowInteropHelper(this).Handle; - NativeMethods.FlashWindow(hWnd, true); + var hWnd = new WindowInteropHelper(this).Handle; + PInvoke.FlashWindow((HWND)hWnd, true); }; } diff --git a/Bloxstrap/Utility/NativeMethods.cs b/Bloxstrap/Utility/NativeMethods.cs deleted file mode 100644 index b869f07..0000000 --- a/Bloxstrap/Utility/NativeMethods.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Bloxstrap.Utility -{ - static class NativeMethods - { - [DllImport("user32.dll")] - public static extern bool SetForegroundWindow(IntPtr hWnd); - - [DllImport("user32.dll")] - public static extern bool FlashWindow(IntPtr hWnd, bool bInvert); - - [DllImport("user32.dll")] - public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex); - - [DllImport("user32.dll")] - public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); - - // i only bothered to add the constants that im using lol - - public const int GWL_EXSTYLE = -20; - - public const int WS_EX_TOOLWINDOW = 0x00000080; - } -}