Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Restore maximized window when a second instance is launched #3437

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading