views:

301

answers:

1

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  A: 

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