c++ - DX9 从全屏切换到窗口给错误的客户区

标签 c++ windows directx

我的 dx9 应用程序有点问题。 当我使用客户区下方的代码从全屏切换回窗口模式时,它的大小不正确,它变小了。 AdjustWindowRect 函数正在正确执行其任务,但 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 标志可以阻止这种情况发生,客户端大小将是您想要的。

关于c++ - DX9 从全屏切换到窗口给错误的客户区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45995772/

相关文章:

c++ - 我应该分配还是重置一个 unique_ptr?

C++:使用 LB_GETCURSEL 和 LB_GETTEXT 从列表框中获取信息

c++ - HLSL 缓冲区步幅和线程 - 这里发生了什么?

c++ - 将 mem_fun_ref 与 boost::shared_ptr 一起使用

c++ - move 赋值运算符和 `if (this != &rhs)`

c++ - 如何调用使用 IDispatch.Invoke 接收浮点值的函数?

python - 是否可以在没有任何标志的情况下使用 argparse ?

c# - 对多个类执行单个 WMI 查询,这可能吗?

屏幕外的 JavaFx 视频尺寸

c++ - DirectX10 交换链和设备指向 0x00000000(导致运行时错误)(c++)