DX9从全屏切换到窗口,给出了错误的客户端区域

DX9 switching from full screen to window give wrong client area

本文关键字:错误 区域 客户端 窗口 DX9      更新时间:2023-10-16

在我的DX9应用程序中有一些问题。当我使用客户端区域下方的代码从全屏切换到窗口模式不是正确的尺寸时,它较小。调整WindowRect函数正在正确执行任务,但SetWindowPos没有设置正确的窗口大小。也许我错过了一些东西。任何想法。

if (d3dpp.Windowed && resChoice == resolutionchoice) return false; // already in window mode and same resolution
                                    //MessageBox(NULL, L"switching to window", L"ERROR", MB_OK);
        resChoice = resolutionchoice;
        screenWidth = resolutionwidth[resChoice];
        screenHeight = resolutionheight[resChoice];
        d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;    // set the back buffer format to 32-bit
        d3dpp.BackBufferWidth = screenWidth;    // set the width of the buffer
        d3dpp.BackBufferHeight = screenHeight;    // set the height of the buffer
        d3dpp.Windowed = true;
        SetWindowLong(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW); // WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_MINIMIZEBOX );
        // need to call SetWindowPos as well
        string values;
        RECT r = { 0,0,screenWidth,screenHeight };
        AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, false);
        values = std::to_string(r.left);
        OutputDebugStringA("Adjust area = ");
        OutputDebugStringA(values.c_str()); OutputDebugStringA(",");
        values = std::to_string(r.top);
        OutputDebugStringA(values.c_str()); OutputDebugStringA(",");
        values = std::to_string(r.right);
        OutputDebugStringA(values.c_str()); OutputDebugStringA(",");
        values = std::to_string(r.bottom);
        OutputDebugStringA(values.c_str()); OutputDebugStringA("n"); 
        SetWindowPos(hWnd, HWND_TOP, r.left, r.top, r.right - r.left , r.bottom - r.top,  SWP_NOZORDER | SWP_SHOWWINDOW | SWP_FRAMECHANGED);//
        //screenWidth = SCREEN_WIDTH;
        //screenHeight = SCREEN_HEIGHT;
        //windowXscale = 1;
        //windowYscale = 1;
        GetClientRect(hWnd, &r);
        values = std::to_string(r.left);
        OutputDebugStringA("Client area = ");
        OutputDebugStringA(values.c_str()); OutputDebugStringA(",");
        values = std::to_string(r.top);
        OutputDebugStringA(values.c_str()); OutputDebugStringA(",");
        values = std::to_string(r.right);
        OutputDebugStringA(values.c_str()); OutputDebugStringA(",");
        values = std::to_string(r.bottom);
        OutputDebugStringA(values.c_str()); OutputDebugStringA("n");
    }

在进行更多搜索后发现,如果您使用setWindowpos,并尝试制作一个比桌面更大的窗口,或者在这种情况下从全屏幕返回时,Windows将发送一条消息和窗口尺寸将自动调整,以使其大于当前桌面尺寸。

在setWindowpos api呼叫中添加swp_nosendchanging flag停止了此操作,客户大小将是您想要的。