2022-04-18 03:38:33 +00:00
|
|
|
|
using System;
|
2021-12-14 05:40:07 +00:00
|
|
|
|
using System.Drawing;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2021-12-14 05:40:07 +00:00
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.Provider
|
|
|
|
|
{
|
|
|
|
|
public class WindowManager
|
|
|
|
|
{
|
|
|
|
|
public static void ApplyHidePanelTitleBar(IntPtr handle, bool hideTitleBar)
|
|
|
|
|
{
|
2022-01-18 14:58:11 +00:00
|
|
|
|
var currentStyle = PInvoke.GetWindowLong(handle, PInvokeConstant.GWL_STYLE).ToInt64();
|
2021-12-14 05:40:07 +00:00
|
|
|
|
|
|
|
|
|
if (hideTitleBar)
|
2022-01-18 14:58:11 +00:00
|
|
|
|
PInvoke.SetWindowLong(handle, PInvokeConstant.GWL_STYLE, (uint)(currentStyle & ~(PInvokeConstant.WS_CAPTION | PInvokeConstant.WS_SIZEBOX)));
|
2021-12-14 05:40:07 +00:00
|
|
|
|
else
|
2022-01-18 14:58:11 +00:00
|
|
|
|
PInvoke.SetWindowLong(handle, PInvokeConstant.GWL_STYLE, (uint)(currentStyle | (PInvokeConstant.WS_CAPTION | PInvokeConstant.WS_SIZEBOX)));
|
2021-12-14 05:40:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ApplyAlwaysOnTop(IntPtr handle, bool alwaysOnTop, Rectangle panelRectangle)
|
|
|
|
|
{
|
|
|
|
|
if (alwaysOnTop)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
PInvoke.SetWindowPos(handle, new IntPtr(PInvokeConstant.HWND_TOPMOST), panelRectangle.Left, panelRectangle.Top, panelRectangle.Width, panelRectangle.Height, PInvokeConstant.SWP_ALWAYS_ON_TOP);
|
2021-12-14 05:40:07 +00:00
|
|
|
|
else
|
2022-01-27 13:40:04 +00:00
|
|
|
|
PInvoke.SetWindowPos(handle, new IntPtr(PInvokeConstant.HWND_NOTOPMOST), panelRectangle.Left, panelRectangle.Top, panelRectangle.Width, panelRectangle.Height, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ApplyAlwaysOnTop(IntPtr handle, bool alwaysOnTop)
|
|
|
|
|
{
|
|
|
|
|
Rectangle rect;
|
|
|
|
|
PInvoke.GetWindowRect(handle, out rect);
|
|
|
|
|
|
|
|
|
|
Rectangle clientRectangle;
|
|
|
|
|
PInvoke.GetClientRect(handle, out clientRectangle);
|
|
|
|
|
|
|
|
|
|
ApplyAlwaysOnTop(handle, alwaysOnTop, new Rectangle(rect.X, rect.Y, clientRectangle.Width, clientRectangle.Height));
|
2021-12-14 05:40:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CloseWindow(IntPtr handle)
|
|
|
|
|
{
|
2022-01-18 14:58:11 +00:00
|
|
|
|
PInvoke.SendMessage(handle, PInvokeConstant.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MoveWindow(IntPtr handle, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
Rectangle rectangle;
|
|
|
|
|
PInvoke.GetClientRect(handle, out rectangle);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
PInvoke.MoveWindow(handle, x, y, rectangle.Width, rectangle.Height, true);
|
2021-12-14 05:40:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public static void MinimizeWindow(IntPtr handle)
|
|
|
|
|
{
|
|
|
|
|
PInvoke.ShowWindow(handle, PInvokeConstant.SW_MINIMIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void BringWindowToForeground(IntPtr handle)
|
2021-12-14 05:40:07 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
PInvoke.ShowWindowAsync(new HandleRef(null, handle), PInvokeConstant.SW_RESTORE);
|
|
|
|
|
PInvoke.SetForegroundWindow(handle);
|
2021-12-14 05:40:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public static void CloseAllCustomPopoutPanels()
|
2021-12-14 05:40:07 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
PInvoke.EnumWindows(new PInvoke.CallBack(EnumAllCustomPopoutPanels), 1);
|
2021-12-14 05:40:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public static void MinimizeAllPopoutPanels(bool active)
|
2021-12-14 05:40:07 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
if (active)
|
2021-12-14 05:40:07 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
PInvoke.EnumWindows(new PInvoke.CallBack(EnumToMinimizePopoutPanels), 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PInvoke.EnumWindows(new PInvoke.CallBack(EnumToMinimizePopoutPanels), 1);
|
2021-12-14 05:40:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-18 14:58:11 +00:00
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
private static bool EnumToMinimizePopoutPanels(IntPtr hwnd, int index)
|
2022-01-18 14:58:11 +00:00
|
|
|
|
{
|
2022-01-27 13:40:04 +00:00
|
|
|
|
var className = PInvoke.GetClassName(hwnd);
|
|
|
|
|
var caption = PInvoke.GetWindowText(hwnd);
|
|
|
|
|
|
|
|
|
|
if (className == "AceApp" && caption.IndexOf("Microsoft Flight Simulator") == -1) // MSFS windows designation
|
|
|
|
|
{
|
|
|
|
|
if (index == 0)
|
|
|
|
|
PInvoke.ShowWindow(hwnd, PInvokeConstant.SW_MINIMIZE);
|
|
|
|
|
else
|
|
|
|
|
PInvoke.ShowWindow(hwnd, PInvokeConstant.SW_RESTORE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2022-01-18 14:58:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool EnumAllCustomPopoutPanels(IntPtr hwnd, int index)
|
|
|
|
|
{
|
|
|
|
|
var className = PInvoke.GetClassName(hwnd);
|
|
|
|
|
var caption = PInvoke.GetWindowText(hwnd);
|
|
|
|
|
|
|
|
|
|
if (className == "AceApp" && (caption.IndexOf("(Custom)") > -1 || caption == String.Empty)) // Only close non-builtin pop out panels
|
|
|
|
|
{
|
|
|
|
|
WindowManager.CloseWindow(hwnd);
|
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
else if (className == "AceApp" && caption.IndexOf("Microsoft Flight Simulator") == -1) // for builtin pop out (ATC, VFR Map, ect)
|
2022-01-18 14:58:11 +00:00
|
|
|
|
{
|
|
|
|
|
WindowManager.MoveWindow(hwnd, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-12-14 05:40:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|