【问题标题】:win32 CTabctrl: Drawing "child" windows in the active tabwin32 CTabctrl:在活动选项卡中绘制“子”窗口
【发布时间】:2010-09-10 13:10:09
【问题描述】:

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

我从 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

【问题讨论】:

  • 您问题中的代码帮助我正确调整 CTabCtrl 孩子的大小,谢谢!)

标签: mfc z-order ctabctrl


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    它现在已修复 - 问题来自这样一个事实,即在 tabctrl 的调整大小代码中,我使用 movewindow 将子窗口移动到位 - 这改变了子窗口的 zorder。

    【讨论】:

      【解决方案3】:

      这可以在您的窗口或标签出现后解决问题。尝试使用

      this->RedrawWindow();

      在 OnTabChanging() 函数返回之前。

      【讨论】:

        猜你喜欢
        • 2013-04-09
        • 2010-10-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-21
        • 1970-01-01
        • 1970-01-01
        • 2023-01-26
        • 1970-01-01
        相关资源
        最近更新 更多