Move Win32 show/hide/minimize/restore tray-chrome logic (the four user32 P/Invokes, the SW_* constants, and the _isMainWindowHidden flag) into Services/WindowChromeManager, and the DPI-aware bounds save/restore + Maximize logic into Services/WindowPlacementService. MainWindow's MainWindow_Closed now delegates to _placementService.Save(); HideShowMainWindow / MinimizeOrHideMainWindow / HideMainWindowToTray delegate to _chromeManager. Also removes stale PlotBounds/PlotAxisLayout/PlotSeriesSample records that were left behind from the PlotView extraction (dead code; the records now live as private nested types in PlotView). MainWindow shrinks from 1445 to 1362 lines; no behaviour change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
// Copyright (C) LibreHardwareMonitor and Contributors.
|
|
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace LibreHardwareMonitor.Windows.WinUI.Services;
|
|
|
|
internal sealed class WindowChromeManager
|
|
{
|
|
private const int ShowWindowHide = 0;
|
|
private const int ShowWindowShow = 5;
|
|
private const int ShowWindowMinimize = 6;
|
|
private const int ShowWindowRestore = 9;
|
|
|
|
private readonly IntPtr _hwnd;
|
|
|
|
public WindowChromeManager(IntPtr hwnd)
|
|
{
|
|
_hwnd = hwnd;
|
|
}
|
|
|
|
public bool IsHidden { get; private set; }
|
|
|
|
public bool IsHiddenOrMinimizedOrInvisible => IsHidden || !IsWindowVisible(_hwnd) || IsIconic(_hwnd);
|
|
|
|
public void HideToTray()
|
|
{
|
|
IsHidden = true;
|
|
ShowWindow(_hwnd, ShowWindowHide);
|
|
}
|
|
|
|
public void Minimize()
|
|
{
|
|
IsHidden = false;
|
|
ShowWindow(_hwnd, ShowWindowMinimize);
|
|
}
|
|
|
|
public void Restore()
|
|
{
|
|
IsHidden = false;
|
|
ShowWindow(_hwnd, ShowWindowShow);
|
|
// Only un-minimize. The window is hidden to the tray with SW_HIDE while keeping its maximized state, so
|
|
// SW_SHOW alone brings it back as it was; an unconditional SW_RESTORE would also un-maximize it.
|
|
if (IsIconic(_hwnd))
|
|
ShowWindow(_hwnd, ShowWindowRestore);
|
|
}
|
|
|
|
[DllImport("user32.dll")]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
private static extern bool ShowWindow(IntPtr windowHandle, int command);
|
|
|
|
[DllImport("user32.dll")]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
private static extern bool IsWindowVisible(IntPtr windowHandle);
|
|
|
|
[DllImport("user32.dll")]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
private static extern bool IsIconic(IntPtr windowHandle);
|
|
}
|