Skip to content

Commit

Permalink
[EnvironmentVariables] EnvironmentVariables window set to front when …
Browse files Browse the repository at this point in the history
…launched. (microsoft#30226)

* [EnvironmentVariables] EnvironmentVariables window set to front when launched.

* [EnvironmentVariables] BringToForeground function used instead of SetForegroundWindow.

* [EnvironmentVariables] BringToForeground is moved to MainWindow constructor.

* [EnvironmentVariables] Move 'handle' from class field to local variable in MainWindow constructor.
  • Loading branch information
gokcekantarci authored Dec 12, 2023
1 parent cc60511 commit 1daeba7
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EnvironmentVariables.Helpers;
using EnvironmentVariables.Helpers.Win32;
using EnvironmentVariables.ViewModels;
using ManagedCommon;
using Microsoft.UI.Dispatching;
using WinUIEx;

Expand All @@ -30,19 +31,20 @@ public MainWindow()
Title = title;
AppTitleTextBlock.Text = title;

RegisterWindow();
var handle = this.GetWindowHandle();
RegisterWindow(handle);

WindowHelpers.BringToForeground(handle);
}

private static readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
private static NativeMethods.WinProc newWndProc;
private static IntPtr oldWndProc = IntPtr.Zero;

private void RegisterWindow()
private void RegisterWindow(IntPtr handle)
{
newWndProc = new NativeMethods.WinProc(WndProc);

var handle = this.GetWindowHandle();

oldWndProc = NativeMethods.SetWindowLongPtr(handle, NativeMethods.WindowLongIndexFlags.GWL_WNDPROC, newWndProc);
}

Expand Down

0 comments on commit 1daeba7

Please sign in to comment.