easysaesch
easysaesch

Reputation: 169

Border appears on frameless window

I have an app written in Qt and on Windows I handle native events myself, to have a custom window with native feeling.

I'm removing the caption like this, to achieve that the window is also positioned correctly when the taskbars auto-hide option is on.

DWORD style = GetWindowLong (hwnd, GWL_STYLE);
style &= ~WS_CAPTION;
style |= (WS_MAXIMIZEBOX | WS_THICKFRAME);
SetWindowLong (hwnd, GWL_STYLE, style);

..and I hide the border like suggested in the MSDN documentation:

switch (msg)
{
    case WM_NCCALCSIZE:
    {
        // this removes the window frame and title bar we added with WS_THICKFRAME and
        // WS_CAPTION
        *result = 0;
        return true;
    }

    ...

I get a fully functional frameless window BUT when I hit the taskbar the border appears, which I don't want. So does anyone have an idea why this happens and how I could bypass it?

Btw if I don't remove the caption from the style I also have a frameless window and this problem doesn't appear but then I run into other problems.

Upvotes: 1

Views: 720

Answers (1)

zett42
zett42

Reputation: 27756

From SetWindowLong reference:

Certain window data is cached, so changes you make using SetWindowLong will not take effect until you call the SetWindowPos function. Specifically, if you change any of the frame styles, you must call SetWindowPos with the SWP_FRAMECHANGED flag for the cache to be updated properly.

Call SetWindowPos like this to fix the problem:

SetWindowPos( hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );

This will also cause Windows to send a WM_NCCALCSIZE message to your window to recalculate the NC area.

Upvotes: 1

Related Questions