给树控件加入工具提示

1.首先给树控件加入TVS_INFOTIP属性风格,如下所示:

if (!m_ctrlTree.Create(WS_CHILD|WS_VISIBLE|
   TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_SHOWSELALWAYS|TVS_INFOTIP, //加入提示TVS_INFOTIP,jingzhou xu(树控件ID:100)
      CRect(0, 0, 0, 0), &m_wndTreeBar, 100))
   {
      TRACE0("Failed to create instant bar child/n");
      return -1;
   }

2.其次加入映射消息声明,如下所示:

afx_msg void OnGetInfoTip(NMHDR* pNMHDR,LRESULT* pResult);       //树控件上加入提示消息,jingzhou xu    

ON_NOTIFY(TVN_GETINFOTIP, 100, OnGetInfoTip)              //树控件条目上加入提示,jingzhou xu

3.最后加入呼应涵数处理:

void CCreateTreeDlg::OnGetInfoTip(NMHDR* pNMHDR, 
                                    LRESULT* pResult) 
  {
  *pResult = 0;
  NMTVGETINFOTIP* pTVTipInfo = (NMTVGETINFOTIP*)pNMHDR;
  LPARAM itemData = (DWORD) pTVTipInfo->lParam;
  //对应每个条目的数据
  HTREEITEM hItem = pTVTipInfo->hItem;
  CString tip;
  HTREEITEM hRootItem = m_chassisTree.GetRootItem();
  if (hRootItem != pTVTipInfo->hItem)
  {
    tip = "树结点的提示";
  }
  else
  {
    tip = "树根上的提示";
  }
  strcpy(pTVTipInfo->pszText, (LPCTSTR) tip);
}

你可能感兴趣的:(给树控件加入工具提示)