From 691aebc4cd159087b4a17eb6d0ce815cd762df04 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Mon, 15 Jul 2024 22:08:50 +0200 Subject: [PATCH] restore maximized window when a second instance is launched (#3437) --- src/App.xaml.cs | 11 +++++------ src/NativeMethods.txt | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/App.xaml.cs b/src/App.xaml.cs index 751bc53c75..4f1346e05f 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -25,16 +25,15 @@ using DevHome.Utilities.Extensions; using DevHome.ViewModels; using DevHome.Views; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.UI.Dispatching; -using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using Microsoft.Windows.AppLifecycle; using Serilog; using Windows.Win32; using Windows.Win32.Foundation; +using Windows.Win32.UI.WindowsAndMessaging; namespace DevHome; @@ -185,14 +184,14 @@ public void ShowMainWindow() { _dispatcherQueue.TryEnqueue(() => { - var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(MainWindow); - if (PInvoke.IsIconic(new HWND(hWnd)) && MainWindow.AppWindow.Presenter is OverlappedPresenter overlappedPresenter) + var hWnd = new HWND(WinRT.Interop.WindowNative.GetWindowHandle(MainWindow)); + if (PInvoke.IsIconic(hWnd)) { - overlappedPresenter.Restore(true); + PInvoke.ShowWindow(hWnd, SHOW_WINDOW_CMD.SW_RESTORE); } else { - PInvoke.SetForegroundWindow(new HWND(hWnd)); + PInvoke.SetForegroundWindow(hWnd); } }); } diff --git a/src/NativeMethods.txt b/src/NativeMethods.txt index a9d9b63b5c..3c66df6aa1 100644 --- a/src/NativeMethods.txt +++ b/src/NativeMethods.txt @@ -3,4 +3,5 @@ GlobalMemoryStatusEx GetSystemInfo CoCreateInstance SetForegroundWindow -IsIconic \ No newline at end of file +IsIconic +ShowWindow \ No newline at end of file