I recently created a window with C++ and the Win32 API. I want to make a custom titlebar for it (I overrode WM_NCHITTEST
to be able to drag it anywhere):
#include <windows.h>
LRESULT CALLBACK window_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
if (uMsg == WM_NCHITTEST) {
LRESULT hit = DefWindowProc(hWnd, uMsg, wParam, lParam);
if (hit == HTCLIENT) hit = HTCAPTION;
return hit;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
WNDCLASSW window_class = {
NULL, window_proc, NULL,NULL, hInstance,
NULL, LoadCursor(NULL, IDC_ARROW),
NULL, NULL, L"minimal_example_window"
}; RegisterClassW(&window_class);
HWND hWnd = CreateWindowW(
L"minimal_example_window", L"",
WS_VISIBLE | WS_POPUP | WS_SIZEBOX | WS_MAXIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
1200,
800,
NULL,NULL,
hInstance,
NULL
);
MSG msg; while (GetMessageW(&msg, NULL, 0, 0) > 0)
{ TranslateMessage(&msg); DispatchMessageW(&msg); }
return 0;
}
But, when I do not have the WS_SIZEBOX
(or WS_THICKFRAME
) and the WS_MAXIMIZEBOX
style on the window, dragging it to the top of the screen doesn't trigger Windows 11's dock popup.
I tried a lot of different window styles listed in Window Styles Win32 Docs, with no success.
For the record, I use clang++ 17.0.6 x86_64-w64-windows-gnu posix
Any help?
Looks like Windows's docking system requires the window to be resizable. The solution is painting over the original titlebar and creating a custom HitTest function to be able to resize the window normally. This article goes into great detail: https://learn.microsoft.com/en-us/windows/win32/dwm/customframe