title-bar fix
This commit is contained in:
@@ -27,7 +27,7 @@ public static class WinApiHelp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AdjustWindowRect(IntPtr hwnd, ref RECT rc, int dpi)
|
public static void AdjustWindowRectangle(IntPtr hwnd, ref RECT rc, int dpi)
|
||||||
{
|
{
|
||||||
uint style = (uint)GetWindowLongPtr(hwnd, -16); // GWL_STYLE
|
uint style = (uint)GetWindowLongPtr(hwnd, -16); // GWL_STYLE
|
||||||
uint styleEx = (uint)GetWindowLongPtr(hwnd, -20); // GWL_EXSTYLE
|
uint styleEx = (uint)GetWindowLongPtr(hwnd, -20); // GWL_EXSTYLE
|
||||||
@@ -35,13 +35,13 @@ public static class WinApiHelp
|
|||||||
if (Environment.OSVersion.Version >= WindowsTen1607)
|
if (Environment.OSVersion.Version >= WindowsTen1607)
|
||||||
AdjustWindowRectExForDpi(ref rc, style, false, styleEx, (uint)dpi);
|
AdjustWindowRectExForDpi(ref rc, style, false, styleEx, (uint)dpi);
|
||||||
else
|
else
|
||||||
Native.WinApi.AdjustWindowRect(ref rc, style, false);
|
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);
|
AdjustWindowRectangle(hwnd, ref rc, dpi);
|
||||||
|
|
||||||
if (changeTop)
|
if (changeTop)
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ public static class WinApiHelp
|
|||||||
public static int GetTitleBarHeight(IntPtr hwnd, int dpi)
|
public static int GetTitleBarHeight(IntPtr hwnd, int dpi)
|
||||||
{
|
{
|
||||||
RECT rect = new RECT();
|
RECT rect = new RECT();
|
||||||
AdjustWindowRect(hwnd, ref rect, dpi);
|
AdjustWindowRectangle(hwnd, ref rect, dpi);
|
||||||
return -rect.Top;
|
return -rect.Top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -677,14 +677,17 @@ public partial class MainForm : Form
|
|||||||
|
|
||||||
Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
|
Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
|
||||||
var rect = new RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height));
|
var rect = new RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height));
|
||||||
|
|
||||||
AddWindowBorders(Handle, ref rect, GetDpi(Handle), !Player.TitleBar);
|
AddWindowBorders(Handle, ref rect, GetDpi(Handle), !Player.TitleBar);
|
||||||
|
|
||||||
width = rect.Width;
|
width = rect.Width;
|
||||||
height = rect.Height;
|
height = rect.Height;
|
||||||
|
|
||||||
int left = middlePos.X - width / 2;
|
int left = Convert.ToInt32(middlePos.X - width / 2.0);
|
||||||
int top = middlePos.Y - height / 2;
|
int top = Convert.ToInt32(middlePos.Y - height / 2.0);
|
||||||
|
|
||||||
|
if (!Player.TitleBar)
|
||||||
|
top -= Convert.ToInt32(GetTitleBarHeight(Handle, GetDpi(Handle)) / 2.0);
|
||||||
|
|
||||||
Rectangle currentRect = new Rectangle(Left, Top, Width, Height);
|
Rectangle currentRect = new Rectangle(Left, Top, Width, Height);
|
||||||
|
|
||||||
@@ -784,7 +787,7 @@ public partial class MainForm : Form
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
WindowState = FormWindowState.Normal;
|
WindowState = FormWindowState.Normal;
|
||||||
|
|
||||||
if (!Player.WasInitialSizeSet)
|
if (!Player.WasInitialSizeSet)
|
||||||
SetFormPosAndSize();
|
SetFormPosAndSize();
|
||||||
}
|
}
|
||||||
@@ -1101,7 +1104,8 @@ public partial class MainForm : Form
|
|||||||
{
|
{
|
||||||
var nccalcsize_params = Marshal.PtrToStructure<NCCALCSIZE_PARAMS>(m.LParam);
|
var nccalcsize_params = Marshal.PtrToStructure<NCCALCSIZE_PARAMS>(m.LParam);
|
||||||
RECT[] rects = nccalcsize_params.rgrc;
|
RECT[] rects = nccalcsize_params.rgrc;
|
||||||
rects[0].Top = rects[0].Top - GetTitleBarHeight(Handle, GetDpi(Handle));
|
int h = GetTitleBarHeight(Handle, GetDpi(Handle));
|
||||||
|
rects[0].Top = rects[0].Top - h;
|
||||||
Marshal.StructureToPtr(nccalcsize_params, m.LParam, false);
|
Marshal.StructureToPtr(nccalcsize_params, m.LParam, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user