I am attempting to create an application with a custom-drawn title bar, similar to Chrome.
It is done now with DWM : Custom Window Frame Using DWM
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am attempting to create an application with a custom-drawn title bar, similar to Chrome. Therefore, I need to handle WM_NCCALCSIZE
. However, I found that the title bar still appears under certain conditions:
let dpi = unsafe { GetDpiForWindow(handle) };
let frame_x = unsafe { GetSystemMetricsForDpi(SM_CXFRAME, dpi) };
let frame_y = unsafe { GetSystemMetricsForDpi(SM_CYFRAME, dpi) };
let padding = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi) };
// wparam is TRUE so lparam points to an NCCALCSIZE_PARAMS structure
let mut params = lparam.0 as *mut NCCALCSIZE_PARAMS;
let mut requested_client_rect = unsafe { &mut ((*params).rgrc) };
requested_client_rect[0].right -= frame_x + padding;
requested_client_rect[0].left += frame_x + padding;
requested_client_rect[0].bottom -= frame_y + padding;
requested_client_rect[0].top += 2; // If you comment out this line, everything is fine
The reason for this line of code requested_client_rect[0].top += 2
is that on Windows 11, there is a 2-pixel border at the top. Without this line, those two pixels would be obscured:
Without requested_client_rect[0].top += 2
:
With requested_client_rect[0].top += 2
:
However, adding this line causes the title bar to mysteriously reappear on Windows 10:
I am attempting to create an application with a custom-drawn title bar, similar to Chrome.
It is done now with DWM : Custom Window Frame Using DWM
If you want to set the round corners on win11, you could try to use DWMWA_WINDOW_CORNER_PREFERENCE
with DwmSetWindowAttribute
.
However, DWMWA_WINDOW_CORNER_PREFERENCE is supported only starting with Windows 11 Build 22000.
On win10, you could try to use CreateRoundRectRgn
and SetWindowRgn
to set the round corners.