Hey, so finally I was able to find a soluion. Figuring out a solution completely drained my energy
.
Anyway here is the final code that I used to remove the titlebar on windows. I also implemented the same thing for macos and linux but I wont post them since I dont know if they work.
WNDPROC original_proc;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_NCCALCSIZE:
{
// Remove the window's standard sizing border
if (wParam == TRUE && lParam != NULL)
{
NCCALCSIZE_PARAMS* pParams = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
pParams->rgrc[0].top += 1;
pParams->rgrc[0].right -= 2;
pParams->rgrc[0].bottom -= 2;
pParams->rgrc[0].left += 2;
}
return 0;
}
case WM_NCPAINT:
{
// Prevent the non-client area from being painted
return 0;
}
case WM_NCHITTEST:
{
// Expand the hit test area for resizing
const int borderWidth = 8; // Adjust this value to control the hit test area size
POINTS mousePos = MAKEPOINTS(lParam);
POINT clientMousePos = { mousePos.x, mousePos.y };
ScreenToClient(hWnd, &clientMousePos);
RECT windowRect;
GetClientRect(hWnd, &windowRect);
if (clientMousePos.y >= windowRect.bottom - borderWidth)
{
if (clientMousePos.x <= borderWidth)
return HTBOTTOMLEFT;
else if (clientMousePos.x >= windowRect.right - borderWidth)
return HTBOTTOMRIGHT;
else
return HTBOTTOM;
}
else if (clientMousePos.y <= borderWidth)
{
if (clientMousePos.x <= borderWidth)
return HTTOPLEFT;
else if (clientMousePos.x >= windowRect.right - borderWidth)
return HTTOPRIGHT;
else
return HTTOP;
}
else if (clientMousePos.x <= borderWidth)
{
return HTLEFT;
}
else if (clientMousePos.x >= windowRect.right - borderWidth)
{
return HTRIGHT;
}
break;
}
}
return CallWindowProc(original_proc, hWnd, uMsg, wParam, lParam);
}
void disableTitlebar(GLFWwindow* window)
{
HWND hWnd = glfwGetWin32Window(window);
LONG_PTR lStyle = GetWindowLongPtr(hWnd, GWL_STYLE);
lStyle |= WS_THICKFRAME;
lStyle &= ~WS_CAPTION;
SetWindowLongPtr(hWnd, GWL_STYLE, lStyle);
RECT windowRect;
GetWindowRect(hWnd, &windowRect);
int width = windowRect.right - windowRect.left;
int height = windowRect.bottom - windowRect.top;
original_proc = (WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC);
(WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WindowProc));
SetWindowPos(hWnd, NULL, 0, 0, width, height, SWP_FRAMECHANGED | SWP_NOMOVE);
}
With this code, you can basically keep all the native functionnality of glfw and windows like snapping the window or resizing and I think you still have rounded corners in windows11(I have to verify that).