如何修改CToolTipCtrl的工具矩形?

发布于 2024-07-20 12:20:51 字数 1316 浏览 4 评论 0原文

这个问题与此相关

在 CDockablePane 派生类中,我有一个 CTreeCtrl 成员,我在 OnCreate() 中为其添加了一个工具提示:

int CMyPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDockablePane::OnCreate(lpCreateStruct) == -1)
        return -1;

    const DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
        TVS_CHECKBOXES | TVS_DISABLEDRAGDROP | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT |
        TVS_INFOTIP | TVS_NOHSCROLL | TVS_SHOWSELALWAYS;

    if(!m_tree.Create(dwStyle, m_treeRect, this, TREECTRL_ID) ) { return -1; }

    m_pToolTip->AddTool(&m_tree, LPSTR_TEXTCALLBACK, &m_treeRect, TREECTRL_ID);
    m_tree.SetToolTips(m_pToolTip);


    return 0;
}

我必须使用所有可选参数调用 AddTool(),因为默认值不适用于 CDockablePane。
m_treeRect 是 CTor 中设置为 (0, 0, 10000, 10000)CRect 成员。 这实在是太难看了。

我想在 m_tree 的大小发生变化时调整工具的矩形。
所以我在 CMyPane::OnSize() 中尝试了一些东西,但没有一个起作用:

  • 调用 m_pToolTip->GetToolInfo() 然后修改 CToolInfo > 的 rect 成员,然后调用 SetToolInfo()
  • 调用 m_pToolTip->SetToolRect()

这是如何完成的?

This question is related to this one.

In a CDockablePane derived class I have a CTreeCtrl member for which I add a ToolTip in OnCreate():

int CMyPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDockablePane::OnCreate(lpCreateStruct) == -1)
        return -1;

    const DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
        TVS_CHECKBOXES | TVS_DISABLEDRAGDROP | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT |
        TVS_INFOTIP | TVS_NOHSCROLL | TVS_SHOWSELALWAYS;

    if(!m_tree.Create(dwStyle, m_treeRect, this, TREECTRL_ID) ) { return -1; }

    m_pToolTip->AddTool(&m_tree, LPSTR_TEXTCALLBACK, &m_treeRect, TREECTRL_ID);
    m_tree.SetToolTips(m_pToolTip);


    return 0;
}

I have to call AddTool() with all of the optional parameters because the default values won't work with CDockablePane.
m_treeRect is a CRect member set to (0, 0, 10000, 10000) in the CTor. This is really ugly.

I would like to adjust the tool's rectangle whenever m_tree's size changes.
So I tried some stuff in CMyPane::OnSize() but none of it worked:

  • Calling m_pToolTip->GetToolInfo() then modify the CToolInfo's rect member, then calling SetToolInfo()
  • Calling m_pToolTip->SetToolRect()

How is it meant to be done?

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

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

发布评论

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

评论(2

青朷 2024-07-27 12:20:51

我不知道除了在 OnSize 处理程序中再次调用 DelTool 然后再次调用 AddTool 之外,没有其他方法可以做到这一点:

void CMyPane::OnSize(UINT nType, int cx, int cy)
{
    CDockablePane::OnSize(nType, cx, cy);

    if (m_pToolTip != NULL)
    {
        m_pToolTip->DelTool(&m_tree, TREECTRL_ID);

        CRect treeRect;
        m_tree.GetClientRect(treeRect);

        m_pToolTip->AddTool(&m_tree, LPSTR_TEXTCALLBACK, &treeRect, TREECTRL_ID);
    }
}

I know no other way to do this other than calling DelTool then AddTool again in your OnSize handler:

void CMyPane::OnSize(UINT nType, int cx, int cy)
{
    CDockablePane::OnSize(nType, cx, cy);

    if (m_pToolTip != NULL)
    {
        m_pToolTip->DelTool(&m_tree, TREECTRL_ID);

        CRect treeRect;
        m_tree.GetClientRect(treeRect);

        m_pToolTip->AddTool(&m_tree, LPSTR_TEXTCALLBACK, &treeRect, TREECTRL_ID);
    }
}
与他有关 2024-07-27 12:20:51
int CMyPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDockablePane::OnCreate(lpCreateStruct) == -1)
        return -1;

    const DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
        TVS_CHECKBOXES | TVS_DISABLEDRAGDROP | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT |
        TVS_INFOTIP | TVS_NOHSCROLL | TVS_SHOWSELALWAYS;

    if(!m_tree.Create(dwStyle, m_treeRect, this, TREECTRL_ID) ) { return -1; }

    m_pToolTip->AddTool(&m_tree, LPSTR_TEXTCALLBACK, &m_treeRect, TREECTRL_ID);
    m_tree.SetToolTips(m_pToolTip);


    return 0;
}
int CMyPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDockablePane::OnCreate(lpCreateStruct) == -1)
        return -1;

    const DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
        TVS_CHECKBOXES | TVS_DISABLEDRAGDROP | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT |
        TVS_INFOTIP | TVS_NOHSCROLL | TVS_SHOWSELALWAYS;

    if(!m_tree.Create(dwStyle, m_treeRect, this, TREECTRL_ID) ) { return -1; }

    m_pToolTip->AddTool(&m_tree, LPSTR_TEXTCALLBACK, &m_treeRect, TREECTRL_ID);
    m_tree.SetToolTips(m_pToolTip);


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