[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

ToolTips w/ TreeView...

Dum qwestion but... Get tool tips to work with CTreeView within CMDIChildWnd...
0
muffinthedog
Asked:
muffinthedog
1 Solution
 
proskigCommented:
From codeguru:
Changing the tool tip as the mouse pointer moves along different tree control items is fairly simple. The tree control can be on a dialog, property page or a form view. Assuming that you use a class derived from CFormView called CMyFormView, which has a tree control, the steps to follow are:

Declare a member variable for the tree control (IDC_TREE1), m_tree.
Decide on how the tip for each tree item will be stored. For instance, you could hold the tip in a map which you declare in the header file CMyFormView.h.

      CMap< HTREEITEM,HTREEITEM&,CString,CString& > tooltipMap;
Fill the map as you generate the items of the tree. For instance after every InsertItem:
      HTREEITEM hItem = m_tree.InsertItem(&tvItem); // tvItem is of type TV_INSERTSTRUCT
      tooltipMap[hItem] = " Tool Tip Text   ";   // Set the tool tip text of the item.
      
Declare an object of CToolTipCtrl in the header file CMyFormView .h
      CToolTipCtrl m_tooltip;
Create the tool tip control and initialize it in the OnInitialUpdate message handler (OnInitDialog for CDialog derived classes)
      m_tooltip.Create(this);
      m_tooltip.Activate(TRUE);
      m_tooltip.AddTool(GetDlgItem(IDC_TREE1), "Tree Tool Tip");
      
Override the PreTranslateMessage in the form view.
      BOOL CMyFormView::PreTranslateMessage(MSG* pMsg)
      {
            // TODO: Add your specialized code here and/or call the base class
            if(pMsg->message == WM_MOUSEMOVE && pMsg->hwnd == m_tree.m_hWnd)
            {
            CPoint point(LOWORD(pMsg->lParam),HIWORD(pMsg->lParam));
                  HTREEITEM hItem = m_tree.HitTest(point);
                  if(hItem != NULL)
                  {
                        CString text = tooltipMap[hItem];                        
                        m_tooltip.UpdateTipText(text,&m_tree);
                        m_tooltip.RelayEvent(pMsg);
                  }
                  
            }
      }
      
This changes the tool tip text as the mouse pointer moves along the different items in the tree control.
0
 
muffinthedogAuthor Commented:
Worked with minor mod for CTreeView...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now