Skip to content

Commit

Permalink
restore maximized window when a second instance is launched (#3437)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti authored Jul 15, 2024
1 parent 0992c78 commit 691aebc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ GlobalMemoryStatusEx
GetSystemInfo
CoCreateInstance
SetForegroundWindow
IsIconic
IsIconic
ShowWindow

0 comments on commit 691aebc

Please sign in to comment.