win32-window-custom-titlebar
win32-window-custom-titlebar copied to clipboard
Maximized window style at startup visual flickering
Nice example of a custom titlebar!
One thing I noticed, when starting the Window in maximized position: a little flickering at the top, as if the window is too big and than quickly switching to the right size. (I tested this on Windows 10 latest version, and Windows 11).
I haven't found a fix for this yet, maybe anyone else with a suggestion?
Hi,
You can try to handle NCLBUTTONDOWN to replace default maximize and minimize using MoveWindow to reduce flickering at the top.
My find out a solution to reduce flickering : Perform ncpaint to paint all extended client rect. Below is my code for your information:
LRESULT OnNCPaint() {
int borderSize = 5;
HDC dc = GetWindowDC(*this);
RECT rc;
GetClientRect(*this, &rc);
rc.left -= borderSize;
rc.right += borderSize * 2;
rc.bottom += borderSize;
SetBkMode(dc,TRANSPARENT);
FillRect(dc,rc, CreateSolidBrush(RGB(0,0,0))); // Color should same as with title color.
return 0;
}
And you need to change your nccalsize as below:
NCCALCSIZE_PARAMS* params = (NCCALCSIZE_PARAMS*)lparam;
RECT* clientRect = params->rgrc;
if (IsMaximized(handle)) {
clientRect->top += padding;
clientRect->right -= padding + frameX;
clientRect->left += padding + frameX;
clientRect->bottom -= padding + frameY;
}
else {
clientRect->right -= borderSize;// frameX + padding;
clientRect->left += borderSize;// frameX + padding;
clientRect->bottom -= borderSize;// frameY + padding;
}
The simplest method is change background HBRUSH's color as title bar color . hBrush = CreateSolidBrush(title_bar_color); SetClassLongPtr(GCLP_HBRBACKGROUND, (LONG_PTR)hBrush);
@kitepad Thank you for posting the code, however it does not seem to solve the problem for me, or maybe I'm just applying it incorrectly. If you could apply your patch and submit a PR with a working code it would be hugely appreciated.
@kitepad Thank you for posting the code, however it doesn't seem to solve the issue at hand at least for me on Win10. If you add WS_MAXIMIZE
to the window_style
to make the window be created in maximized state, you can see the titlebar jumping down a bit. This does not happen if you just manually maximize the window. I suspect that the code needs to have some special handling specifically for this case.
@grassator Same issues is happened on my box when i add WS_MAXIMIZE style. And I have another try is handle WM_NCPAINT to paint all, it seems no white flickering on startup (But my trying is with win32-framework). But have other problems when window is restored.