Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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);
davidegiacometti marked this conversation as resolved.
Show resolved Hide resolved
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