Skip to content

Commit 47550df

Browse files
authored
Merge pull request #32 from damywise/patch-1
Fix WM_NCCALCSIZE,WM_NCHITTEST: All Border Resize
2 parents ffb5e4f + 4f4e27b commit 47550df

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)