c++ SetWindowRgn将窗口主题更改为经典

nlejzf6q  于 2023-03-25  发布在  其他
关注(0)|答案(1)|浏览(148)

当我在windows API代码中使用SetWindowRgn函数时,创建的windows样式从Modern变为Classic。
在此处重现问题的最小代码:

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;
}

注解和取消注解下面的行将演示问题

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

现代(注解行):

经典(取消注解行):

你知道函数中到底是什么导致了这个问题吗?有什么解决方法吗?

vi4fp9gy

vi4fp9gy1#

当使用SetWindowRgn时,* 系统假设具有非NULL区域的窗口是不使用视觉样式的专用窗口 *。
请选中“未应用视觉样式时”。

相关问题