Mfc win32 CTabctrl:绘图“;“儿童”;活动选项卡中的窗口

Mfc win32 CTabctrl:绘图“;“儿童”;活动选项卡中的窗口,mfc,z-order,ctabctrl,Mfc,Z Order,Ctabctrl,我有一个可调整大小的对话框,其中包含一个CTabCtrl,选项卡控件有4个选项卡,单击该选项卡时会显示四个不同的CTREETRL之一 我从CTabCtrl派生了一个类,它跟踪其“子”控件,如下所示: ... class Container: public CTabCtrl { vector<CWnd*> _children; .... int Container::AddTab(CWnd* Child) { CString txt;Child->GetWindowText(t

我有一个可调整大小的对话框,其中包含一个CTabCtrl,选项卡控件有4个选项卡,单击该选项卡时会显示四个不同的CTREETRL之一

我从CTabCtrl派生了一个类,它跟踪其“子”控件,如下所示:

...
class Container: public CTabCtrl {
vector<CWnd*> _children;
....
int Container::AddTab(CWnd* Child) {
 CString txt;Child->GetWindowText(txt);
 _children.push_back(Child);
 int idx = this->InsertItem(this->GetItemCount(), txt, 0);
 if(idx == 0) {
  CRect c;
  this->GetWindowRect(&c);
  GetParent()->ScreenToClient(&c);
  this->AdjustRect(FALSE, c);
  Child->SetWindowPos(&wndTop, c.left, c.top, c.Width(), c.Height(), SWP_SHOWWINDOW);
  this->SetCurSel(idx);
 } else Child->ShowWindow(SW_HIDE);
 return idx;
}
void Container::OnTabChanging(NMHDR*, LRESULT* pResult)  { // hide the changed from tab
    int selected = this->GetCurSel();
    if(selected != -1)
    {
        // move old window to bottom of the zorder and hide
        _children[selected]->SetWindowPos(&wndBottom, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_HIDEWINDOW);
        ASSERT(!_children[selected]->IsWindowVisible());
    }
    *pResult = 0;
}
// show the child for the tab being changed to
void CNodeContainer::OnTabChanged(NMHDR* pNMHDR, LRESULT* pResult) {
 int selected = this->GetCurSel();
 ASSERT(selected!=-1);
 CRect c;
 this->GetWindowRect(&c);
 GetParent()->ScreenToClient(&c);
 this->AdjustRect(FALSE, c);
 _children[selected]->SetWindowPos(&wndTop, c.left, c.top, c.Width(), c.Height(), SWP_SHOWWINDOW|SWP_FRAMECHANGED);
 *pResult = 0;
}
然而,虽然子控件出现,但它们并不总是正确绘制,它们将其内容混合在一起,只有在我单击它们时才显示正确的内容(实际的树控件)

这是在zorder中绘制和移动窗口的最佳方式吗?我遗漏了什么

非常感谢


bg

这可以解决窗口或选项卡关闭后的问题。尝试使用

此->重画窗口()


在返回之前,在OnTabChanging()函数中执行此操作。

不只是更改子项的z顺序,而是完全隐藏除最上面的子项之外的所有子项。我在自定义CTabCtrl中使用了相同的方法,效果很好。

它现在已经修复了-问题是因为在tabctrl的调整大小代码中,我使用movewindow将子窗口移动到位-这改变了子窗口的顺序

您问题中的代码帮助我正确调整了CTabCtrl儿童的大小,谢谢!)