How to Use Tree-View Infotips

When you apply the TVS_INFOTIP style to a tree-view control, it generates TVN_GETINFOTIP notifications when the cursor is over an item in the tree view. By responding to this notification, you can set the text that appears in the infotip.

What you need to know

Technologies

Prerequisites

  • C/C++
  • Windows User Interface Programming

Instructions

Use Tree-View Infotips

The following example code shows how an application might respond to the notification. For simplicity, the example just copies the text for the item to the infotip.

  case WM_NOTIFY:
    switch (((LPNMHDR) lParam)->code)
    {
    case TVN_GETINFOTIP:
        {
          LPNMTVGETINFOTIP pTip = (LPNMTVGETINFOTIP)lParam;
          HWND hTree            = GetDlgItem(hDlg, IDC_TREE1);
          HTREEITEM item        = pTip->hItem;

          // Get the text for the item.
          TVITEM tvitem;
          tvitem.mask       = TVIF_TEXT;
          tvitem.hItem      = item;
          TCHAR temp[1024];
          tvitem.pszText    = infoTipBuf;
          tvitem.cchTextMax = sizeof(temp) / sizeof(TCHAR);
          TreeView_GetItem(hTree, &tvitem);

          // Copy the text to the infotip.
          wcscpy_s(pTip->pszText, pTip->cchTextMax, tvitem.pszText);
          break;
        }
      }
      return TRUE;

Using Tree-View Controls

CustDTv sample illustrates custom draw in a Tree-View control