win32 CTabctrl:绘制“子”活动选项卡中的窗口

发布于 2024-09-18 18:13:18 字数 1737 浏览 11 评论 0原文

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

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

I have a resizable dialog that contains a CTabCtrl, the tab control has 4 tabs that when clicked on displays one of four different CTreeCtrls.

I have derived a class from CTabCtrl, which keeps track of its "child" controls like so:

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

And I attempt to draw the child controls like so:

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

However the child controls, whilst they appear, don't always draw correctly, they sort of mix up their content together and only show the right content when i click on them (the actual tree controls).

Is this the best way of drawing and moving windows around in the zorder, what am I missing?

Many thanks

bg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怂人 2024-09-25 18:13:18

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

Instead of just changing the z-order of your children, completely hide every child except the top one. I use the same approach in a custom CTabCtrl and it works fine.

゛清羽墨安 2024-09-25 18:13:18

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

Its fixed now - the problem came from the fact that the in the resize code for the tabctrl, I was using movewindow to move the child windows into place - This was changing the zorder of the child windows.

痞味浪人 2024-09-25 18:13:18

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

这个->RedrawWindow();

在 OnTabChanging() 函数返回之前。

This could solve the problem after your window or tab apears. Try to use

this->RedrawWindow();

In OnTabChanging() function before it returns.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文