Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Commit

Permalink
Fixing issue #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkol committed Jan 1, 2022
1 parent 1f9d606 commit dfd9a58
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Chromely.CefSharp/NativeHost/WinBase/NativeHostBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,27 @@ private unsafe bool HandleMinMaxSizes(IntPtr lParam)
isHandled = true;
}

// https://stackoverflow.com/questions/39816031/maximize-window-maintaining-taskbar-limits
if (_options.WindowFrameless && _options.WindowState == WindowState.Maximize)
{
IntPtr handle = MonitorFromWindow(GetDesktopWindow(), MONITOR.DEFAULTTONEAREST);

MONITORINFOEXW monInfo = new MONITORINFOEXW(null);
monInfo.cbSize = (uint)Marshal.SizeOf(monInfo);

var captionHeight = GetSystemMetrics(SystemMetric.SM_CYCAPTION);

GetMonitorInfoW(handle, ref monInfo);
var workArea = monInfo.rcWork;
var monitorArea = monInfo.rcMonitor;
mmi->ptMaxPosition.X = Math.Abs(workArea.left - monitorArea.left) - captionHeight / 2;
mmi->ptMaxPosition.Y = Math.Abs(workArea.top - monitorArea.top);
mmi->ptMaxSize.X = Math.Abs(workArea.right - workArea.left) + captionHeight;
mmi->ptMaxSize.Y = Math.Abs(workArea.bottom - workArea.top) + captionHeight;

isHandled = true;
}

return isHandled;
}

Expand Down
15 changes: 15 additions & 0 deletions src/Chromely.CefSharp/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,35 @@ public virtual void Minimize()
{
if (Handle != IntPtr.Zero)
{
if (_config.WindowOptions.WindowFrameless)
{
_config.WindowOptions.WindowState = WindowState.Minimize;
}

ShowWindow(Handle, SW.SHOWMINIMIZED);
}
}
public virtual void Maximize()
{
if (Handle != IntPtr.Zero)
{
if (_config.WindowOptions.WindowFrameless)
{
_config.WindowOptions.WindowState = WindowState.Maximize;
}

ShowWindow(Handle, SW.SHOWMAXIMIZED);
}
}
public virtual void Restore()
{
if (Handle != IntPtr.Zero)
{
if (_config.WindowOptions.WindowFrameless)
{
_config.WindowOptions.WindowState = WindowState.Normal;
}

ShowWindow(Handle, SW.RESTORE);
}
}
Expand Down

0 comments on commit dfd9a58

Please sign in to comment.