Support of the mpv option title-bar

This commit is contained in:
stax76
2023-12-22 18:35:07 +01:00
parent 0ef679e00d
commit 3e4ea03437
8 changed files with 78 additions and 126 deletions

View File

@@ -27,33 +27,33 @@ public static class WinApiHelp
}
}
public static void AdjustWindowRect(IntPtr hwnd, ref Rect rc, int dpi)
public static void AdjustWindowRect(IntPtr hwnd, ref RECT rc, int dpi)
{
uint windowStyle = (uint)GetWindowLong(hwnd, -16); // GWL_STYLE
uint windowStyleEx = (uint)GetWindowLong(hwnd, -20); // GWL_EXSTYLE
uint style = (uint)GetWindowLongPtr(hwnd, -16); // GWL_STYLE
uint styleEx = (uint)GetWindowLongPtr(hwnd, -20); // GWL_EXSTYLE
if (Environment.OSVersion.Version >= WindowsTen1607)
AdjustWindowRectExForDpi(ref rc, windowStyle, false, windowStyleEx, (uint)dpi);
AdjustWindowRectExForDpi(ref rc, style, false, styleEx, (uint)dpi);
else
Native.WinApi.AdjustWindowRect(ref rc, windowStyle, false);
Native.WinApi.AdjustWindowRect(ref rc, style, false);
}
public static void AddWindowBorders(IntPtr hwnd, ref Rect rc, int dpi, bool changeTop)
public static void AddWindowBorders(IntPtr hwnd, ref RECT rc, int dpi, bool changeTop)
{
Rect win = rc;
RECT win = rc;
AdjustWindowRect(hwnd, ref rc, dpi);
if (changeTop)
{
int top = rc.Top;
top -= rc.Top - win.Top;
rc = new Rect(rc.Left, top, rc.Right, rc.Bottom);
rc = new RECT(rc.Left, top, rc.Right, rc.Bottom);
}
}
public static void SubtractWindowBorders(IntPtr hwnd, ref Rect rc, int dpi, bool changeTop)
public static void SubtractWindowBorders(IntPtr hwnd, ref RECT rc, int dpi, bool changeTop)
{
Rect r = new Rect();
RECT r = new RECT();
AddWindowBorders(hwnd, ref r, dpi, changeTop);
rc.Left -= r.Left;
rc.Top -= r.Top;
@@ -63,15 +63,15 @@ public static class WinApiHelp
public static int GetTitleBarHeight(IntPtr hwnd, int dpi)
{
Rect r = new Rect();
AdjustWindowRect(hwnd, ref r, dpi);
return -r.Top;
RECT rect = new RECT();
AdjustWindowRect(hwnd, ref rect, dpi);
return -rect.Top;
}
public static Rectangle GetWorkingArea(IntPtr handle, Rectangle workingArea)
{
if (handle != IntPtr.Zero && GetDwmWindowRect(handle, out Rect dwmRect) &&
GetWindowRect(handle, out Rect rect))
if (handle != IntPtr.Zero && GetDwmWindowRect(handle, out RECT dwmRect) &&
GetWindowRect(handle, out RECT rect))
{
int left = workingArea.Left;
int top = workingArea.Top;
@@ -89,28 +89,12 @@ public static class WinApiHelp
return workingArea;
}
public static bool GetDwmWindowRect(IntPtr handle, out Rect rect)
public static bool GetDwmWindowRect(IntPtr handle, out RECT rect)
{
const uint DWMWA_EXTENDED_FRAME_BOUNDS = 9;
return 0 == DwmGetWindowAttribute(handle, DWMWA_EXTENDED_FRAME_BOUNDS,
out rect, (uint)Marshal.SizeOf<Rect>());
}
public static IntPtr GetWindowLong(IntPtr hWnd, int nIndex)
{
if (IntPtr.Size == 8)
return GetWindowLongPtr(hWnd, nIndex);
else
return GetWindowLong32(hWnd, nIndex);
}
public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong)
{
if (IntPtr.Size == 8)
return SetWindowLongPtr(hWnd, nIndex, dwNewLong);
else
return SetWindowLong32(hWnd, nIndex, dwNewLong);
out rect, (uint)Marshal.SizeOf<RECT>());
}
public static string GetAppPathForExtension(params string[] extensions)