BorderlessWindow icon indicating copy to clipboard operation
BorderlessWindow copied to clipboard

How to remove the round corners

Open CybernetHacker14 opened this issue 3 years ago • 1 comments

I am trying to render an ImGui dockspace, and using certain parts of your code in combination with glfw.

However, the resulting window has round corners, and hence, it might be introducing certain padding/space. Screenshot_1

How do I remove the round corners? I need to test whether this is causing that gap.

CybernetHacker14 avatar Nov 03 '22 16:11 CybernetHacker14

It looks like you're on Windows 11. You can use DWM calls to turn off the rounded corners if needed. Something like this:

namespace {
   . . . 
   
   auto set_square_corners(HWND handle) -> void {
        if (composition_enabled()) {
            DWM_WINDOW_CORNER_PREFERENCE no_round_corners{ DWMWCP_DONOTROUND };

            // Will return E_INVALIDARG on non-Windows 11 systems.
            ::DwmSetWindowAttribute(handle, DWMWA_WINDOW_CORNER_PREFERENCE, &no_round_corners, sizeof(no_round_corners));
        }
    }
}

Then in BorderlessWindow::BorderlessWindow(), call it with set_square_corners(handle.get());

You could obviously add code to switch the corners to round/square as desired.

See DWM_WINDOW_CORNER_PREFERENCE enumeration

jschroedl avatar Jan 04 '23 16:01 jschroedl