Skip to content

Commit 4f4e27b

Browse files
authored
Fix WM_NCCALCSIZE,WM_NCHITTEST: All Border Resize
So I did some testing and found that these codes: - Enables resizing from all border sides. - Makes it so that the window doesn't resize that much (reduces only one pixel on the left, right, and bottom border) when changing titleBarStyle to "hidden". - Removing the WM_NCHITTEST makes the edges (top left, bottom right, etc) resize region bigger than it should be. - fOnResizeBorder should've been set to true (it was set to false) to enable resizing from top border. Issues: - The top side originally goes inside the title bar so someone has to figure out how to do that in titleBarStyle = "hidden". The top border IS resizable in titleBarStyle = "hidden" but only for exactly 1 pixel and that is very annoying. - SetResizable makes weird behavior (as usual) during titleBarStyle = "hidden"
1 parent 859ba75 commit 4f4e27b

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

windows/window_manager_plugin.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,39 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd, UINT mes
108108
AdjustWindowRectEx(&borderThickness, GetWindowLongPtr(hWnd, GWL_STYLE) & ~WS_CAPTION, FALSE, NULL);
109109
NCCALCSIZE_PARAMS *sz = reinterpret_cast<NCCALCSIZE_PARAMS *>(lParam);
110110
// Add 1 pixel to the top border to make the window resizable from the top border
111-
sz->rgrc[0].top -= 1;
112-
sz->rgrc[0].right -= (borderThickness.right - 3);
113-
sz->rgrc[0].bottom -= (borderThickness.bottom - 3);
111+
sz->rgrc[0].top += 1;
112+
sz->rgrc[0].right -= borderThickness.right;
113+
sz->rgrc[0].bottom -= borderThickness.bottom;
114+
sz->rgrc[0].left -= borderThickness.left;
114115

115116
return (WVR_HREDRAW | WVR_VREDRAW);
116117
}
118+
}
119+
else if (message == WM_NCHITTEST)
120+
{
121+
LONG width = 10;
122+
POINT mouse = {LOWORD(lParam), HIWORD(lParam)};
123+
RECT window;
124+
GetWindowRect(hWnd, &window);
125+
RECT rcFrame = {0};
126+
// AdjustWindowRectEx(&rcFrame, WS_OVERLAPPEDWINDOW & ~WS_CAPTION, FALSE, NULL);
127+
USHORT x = 1;
128+
USHORT y = 1;
129+
bool fOnResizeBorder = true;
130+
if (mouse.y >= window.top && mouse.y < window.top + width)
131+
x = 0;
132+
else if (mouse.y < window.bottom && mouse.y >= window.bottom - width)
133+
x = 2;
134+
if (mouse.x >= window.left && mouse.x < window.left + width)
135+
y = 0;
136+
else if (mouse.x < window.right && mouse.x >= window.right - width)
137+
y = 2;
138+
LRESULT hitTests[3][3] = {
139+
{HTTOPLEFT, fOnResizeBorder ? HTTOP : HTCAPTION, HTTOPRIGHT},
140+
{HTLEFT, HTNOWHERE, HTRIGHT},
141+
{HTBOTTOMLEFT, HTBOTTOM, HTBOTTOMRIGHT},
142+
};
143+
return hitTests[x][y];
117144
}
118145
else if (message == WM_GETMINMAXINFO)
119146
{

0 commit comments

Comments
 (0)