关于CTreeCtrl上添加CToolTipCtrl

class CTreeCtrlhAssiant
{
public:
 static void AddNode(CMyToolTipCtrl& treeCtrl)
 {
  treeCtrl.m_pToolTipCtrl = new CToolTipCtrl;
  if (!treeCtrl.m_pToolTipCtrl->Create( &treeCtrl, TTS_ALWAYSTIP))
  {
   TRACE(_T("Unable To create ToolTip/n"));
   return ;
  }
  HTREEITEM hmyItem;
  HTREEITEM hsubItem;
  CRect r;
  hmyItem= treeCtrl.InsertItem( _T("item"),0,1 );
  treeCtrl.GetItemRect(hmyItem, r, TRUE);
  treeCtrl.m_pToolTipCtrl->AddTool(&treeCtrl, _T("item1 info"), &r, IDC_TREE1);
  hmyItem=treeCtrl.InsertItem( _T("item2"),0,1 );
  treeCtrl.GetItemRect(hmyItem, r, TRUE);
  treeCtrl.m_pToolTipCtrl->AddTool(&treeCtrl, _T("item2 info"), &r, IDC_TREE1);

  UINT uID = 100;     
  hsubItem = treeCtrl.InsertItem("1111",hmyItem);
  treeCtrl.Expand(hmyItem,TVE_EXPAND);
  treeCtrl.GetItemRect(hsubItem, r, TRUE);
  treeCtrl.m_pToolTipCtrl->AddTool(&treeCtrl, _T("1111 info"), &r, uID);
  hsubItem = treeCtrl.InsertItem("2222",hmyItem);
  treeCtrl.GetItemRect(hsubItem, r, TRUE);
  treeCtrl.m_pToolTipCtrl->AddTool(&treeCtrl, _T("2222 info"), &r, uID);
  hsubItem = treeCtrl.InsertItem("3333",hmyItem);
  treeCtrl.GetItemRect(hsubItem, r, TRUE);
  treeCtrl.m_pToolTipCtrl->AddTool(&treeCtrl, _T("3333 info"), &r, uID);

}
void CMyToolTipCtrl::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult)
{
 NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
 // TODO: Add your control notification handler code here
 TV_ITEM   itm=   pNMTreeView->itemNew;  
   
 if   (itm.state   &   TVIS_EXPANDED)  
 {
  m_pToolTipCtrl->Activate(TRUE);
 }
 else
  m_pToolTipCtrl->Activate(FALSE);
 *pResult = 0;
}
 

你可能感兴趣的:(关于CTreeCtrl上添加CToolTipCtrl)