[EnvironmentVariables] EnvironmentVariables window set to front when launched. (#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.
This commit is contained in:
gokcekantarci
2023-12-12 16:15:26 +03:00
committed by GitHub
parent cc605113cf
commit 1daeba7e77

View File

@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
using EnvironmentVariables.Helpers;
using EnvironmentVariables.Helpers.Win32;
using EnvironmentVariables.ViewModels;
using ManagedCommon;
using Microsoft.UI.Dispatching;
using WinUIEx;
@@ -30,19 +31,20 @@ namespace EnvironmentVariables
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);
}