简体   繁体   English

如何在MFC中的应用程序中对Windows重新排序

[英]How to reorder windows in an application in MFC

Let's say that there are several different Windows ( CWnd ) open in a software, and the pointers to all active windows are saved in std::vector<Node> tabsInfo . 假设在软件中打开了几个不同的Windows( CWnd ),所有活动窗口的指针都保存在std::vector<Node> tabsInfo Here is a portion of code for Node : 这是Node的一部分代码:

struct typedef Node {
...
CWnd *pWnd;
...
}

I have a handler to update the Z-order of all active windows using tabsInfo , which looks like this: 我有一个处理程序,可以使用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
    }

However, when I debug them, even though they run without error, it makes no changes to the ordering of all windows. 但是,当我调试它们时,即使它们没有错误运行,也不会更改所有窗口的顺序。

Am I misunderstanding on how to use SetWindowPos ? 我对使用SetWindowPos误解吗? When I looked other questions answered (which deals with buttons inside dialogs instead of windows), they gave the similar solution, but it doesn't seem to work here. 当我查看其他已回答的问题(涉及对话框而不是窗口中的按钮)时,他们给出了类似的解决方案,但在这里似乎不起作用。

For anyone who have the same problem, I added a few more lines, and it worked: 对于有相同问题的任何人,我都添加了几行内容,并且行得通:

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

Hope it helps someone :) 希望它可以帮助某人:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM