borderless-window icon indicating copy to clipboard operation
borderless-window copied to clipboard

Possibly better way of calculating maximized client rectangle

Open avocadoboi opened this issue 4 years ago • 2 comments

Hello! Thank you for this example, it helped me a lot.

After experimenting a bit, I think I found a better way of calculating the bounding rectangle of the non-client area in WM_NCCALCSIZE. Firstly, add the WS_MAXIMIZEBOX style flag to the window. This enables it to maximize when dragging it towards an edge of the monitor (size snapping), but it also makes the bottom of the window not get obscured by the taskbar. This makes the hacky solution with has_autohide_appbar unnecessary (the shell won't make it full-screen).

In my WM_NCCALCSIZE message, I then just do this:

auto const parameters = reinterpret_cast<NCCALCSIZE_PARAMS*>(p_data_b);

if (IsMaximized(m_windowHandle)) {
	auto info = MONITORINFO{};
	info.cbSize = sizeof(MONITORINFO);
	GetMonitorInfo(MonitorFromRect(parameters->rgrc, MONITOR_DEFAULTTONEAREST), &info);

	parameters->rgrc[0] = info.rcWork;
}

return 0;

to properly fit the client area.

Hope this could help anyone.

avocadoboi avatar Nov 02 '19 17:11 avocadoboi

Do you add the WS_MAXIMIZEBOX style on WM_NCCALCSIZE handler or on the call to CreateWindowEx?

semihartan avatar Dec 31 '20 10:12 semihartan

Just on the call to CreateWindowEx.

avocadoboi avatar Jan 10 '21 09:01 avocadoboi