SetWindowRgn changes window theme to Classic

Viewed 147

When i use the SetWindowRgn function in my windows api code, the created windows style changes from Modern to Classic.

Minumum code to reproduce problem here:

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    
    WNDCLASSEX wc;
    HWND hwnd;

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    hwnd  = CreateWindowEx(
            WS_EX_TOPMOST | WS_EX_CLIENTEDGE,
            g_szClassName,
            "Capture Screen",
            WS_OVERLAPPEDWINDOW, 
            10, 100, 800, 600,
            NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }
    
    ShowWindow(hwnd, SW_NORMAL);
    UpdateWindow(hwnd);

    HRGN WindowRgn = CreateRectRgn(0,0,800,600); 
    SetWindowRgn(hwnd,WindowRgn,TRUE); // <===== comment, uncomment this line to observe difference
    
    MSG Msg;
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

Commenting and uncommenting the line below will demonstrate the problem

    SetWindowRgn(hwnd,WindowRgn,TRUE); // <===== comment, uncomment this line to observe difference

Modern (commenting the line) :

enter image description here

Classic (uncommenting the line) :

enter image description here

Any idea what exactly in the function causes the problem here? And any fixes for this?

0 Answers
Related