How to modify the tool rect of a CToolTipCtrl?

非 Y 不嫁゛ 提交于 2019-12-14 03:48:39

问题


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?


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/867724/how-to-modify-the-tool-rect-of-a-ctooltipctrl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!