Tooltips For Tree Control Items

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:
  1. Declare a member variable for the tree control (IDC_TREE1), m_tree.
  2. 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;
  3. 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.
    	
  4. Declare an object of CToolTipCtrl in the header file CMyFormView .h
    	CToolTipCtrl m_tooltip;
  5. 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"); 
    	
  6. 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.



Comments

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: September 19, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT In response to the rising number of data breaches and the regulatory and legal impact that can occur as a result of these incidents, leading analysts at Forrester Research have developed five important design principles that will help security professionals reduce their attack surface and mitigate vulnerabilities. Check out this upcoming eSeminar and join Chris Sherman of Forrester Research to learn how to deal with the influx of new device …

  • Live Event Date: August 19, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You deployed your app with the Bluemix PaaS and it's gaining some serious traction, so it's time to make some tweaks. Did you design your application in a way that it can scale in the cloud? Were you even thinking about the cloud when you built the app? If not, chances are your app is going to break. Check out this upcoming webcast to learn various techniques for designing applications that will scale successfully in Bluemix, for the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds