c++createwindowexwindow-style

CreateWindowEx creates old (Windows 7) style border on Windows 10


Whenever I create a window with CreateWindowEx(...) (exact parameters can be found in the code below), it shows up like an old style window:

old style window

Only when I start it on a remote desktop, close the connection and reconnect, it changes to the desired Windows 10 style:

new style window

Does it have something to do with the several WM_SETTINGCHANGE messages the application receives when doing this?

Obviously, I want the window to have a modern style upon creation, and not after handling some message.

I've tried different combinations of WS_... style arguments. Oddly enough, the application only reliably shows up with WS_OVERLAPPEDWINDOW | WS_VISIBLE.

I've tried ShowWindow (with various arguments) and UpdateWindow in both orders.

I've also tried messing with the target platform and toolset, but to no avail (using VS2015, v140).

Code snippet:

WNDCLASSEX wc = {sizeof(WNDCLASSEX), NULL, WindowController::globalEventProcessor, 
                 0L, 0L, GetModuleHandle(NULL), NULL,
                 LoadCursor(NULL, IDC_ARROW), NULL, NULL,
                 _T("Window"), NULL};
RegisterClassEx(&wc);

HWND handle = CreateWindowEx(
            NULL,
            wc.lpszClassName,
            _T("Test"),
            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            parentWindow ? parentWindow->getHandle() : NULL,
            NULL,
            wc.hInstance,
            reinterpret_cast<LPVOID>(this)
);

if (handle != NULL)
{
    ... // resizing the window's contents
    UpdateWindow(handle);
}

Solution

  • Strangely enough, the solution seems to be to remove WS_VISIBLE from the style flags, and show the window manually:

    if (handle != NULL)
    {
        ... // resizing the window's contents
        ShowWindow(handle, 1); /* Add this */
        UpdateWindow(handle);
    }
    

    Which I'm 100% sure I've tried already, but suddenly works. Whatever...