Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在MFC中对应用程序中的窗口重新排序_C++_Mfc - Fatal编程技术网

C++ 如何在MFC中对应用程序中的窗口重新排序

C++ 如何在MFC中对应用程序中的窗口重新排序,c++,mfc,C++,Mfc,假设软件中打开了几个不同的窗口(CWnd),指向所有活动窗口的指针保存在std::vector tabsInfo中。以下是节点的部分代码: struct typedef Node { ... CWnd *pWnd; ... } 我有一个处理程序,可以使用tabsInfo更新所有活动窗口的Z顺序,如下所示: for (size_t i = tabsInfo.size(); i > 1; i--) { Node *pN_cur = &tabsInfo.at(i - 1

假设软件中打开了几个不同的窗口(
CWnd
),指向所有活动窗口的指针保存在
std::vector tabsInfo
中。以下是
节点
的部分代码:

struct typedef Node {
...
CWnd *pWnd;
...
}
我有一个处理程序,可以使用
tabsInfo
更新所有活动窗口的Z顺序,如下所示:

for (size_t i = tabsInfo.size(); i > 1; i--) {
        Node *pN_cur = &tabsInfo.at(i - 1);
        Node *pN_next = &tabsInfo.at(i - 2);
        ret = pN_cur->pWnd->SetWindowPos(pN_next->pWnd, NULL, NULL, NULL, NULL, SWP_NOMOVE | SWP_NOSIZE);
        ASSERT(ret != 0); // Sanity check
    }
但是,当我调试它们时,即使它们运行时没有错误,也不会更改所有窗口的顺序

我是否误解了如何使用
SetWindowPos

当我查看其他问题的答案(涉及对话框中的按钮而不是窗口)时,他们给出了类似的解决方案,但在这里似乎不起作用。

对于有相同问题的人,我又添加了几行,效果很好:

for (int i = tabsInfo.size() - 1; i >= 0; i--) {
        Window_Node *pWN = &tabsInfo.at(i);
        if (tabsInfo.at(i).checked) { // Ignore this line. This is program-specific
            WINDOWPLACEMENT wp = {};
            wp.length = sizeof(WINDOWPLACEMENT);
            pWN->pWnd->GetParentFrame()->GetWindowPlacement(&wp);
            wp.showCmd=SW_RESTORE;                                                                                   
            pWN->pWnd->GetParentFrame()->SetWindowPlacement(&wp);
            ret = pWN->pWnd->GetParentFrame()->SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
            ASSERT (ret != 0);
        } else {
        pWN->pWnd->GetParentFrame()->ShowWindow(SW_MINIMIZE);
        }
    }
}

希望它能帮助某些人:)

您试图重新定位的窗口是子窗口、自有窗口还是非自有窗口?它应该是
SetWindowPos(pN_next->pWnd,0,0,0,…)
而不是使用
NULL
(这不是错误,只是混淆)。该用法在其他方面是正确的,但看起来您正在使用选项卡窗口或其他奇怪的操作,因此无法正常工作。