ToolTip:TreeCtrl如何不同的item显示不同的说明

解决方案 »

  1.   

    每一个item都定义相应的说明在tooltip中,或者调用相应的说明用tooltip
      

  2.   

    http://codeguru.com/listview/cell_tooltip.shtml
    经过改写整理后的Codeguru.com上Zafir Anjum的代码
    #if !defined(AFX_CELLTOOLTIPLISTCTRL_H__D0C6B2B8_452A_42CE_B8ED_8650F808E941__INCLUDED_)
    #define AFX_CELLTOOLTIPLISTCTRL_H__D0C6B2B8_452A_42CE_B8ED_8650F808E941__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // CellToolTipListCtrl.h : header file
    ///////////////////////////////////////////////////////////////////////////////
    // CCellToolTipListCtrl windowclass AFX_EXT_CLASS CCellToolTipListCtrl : public CListCtrl
    {
    // Construction
    public:
    CCellToolTipListCtrl();// Attributes
    public:// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CCellToolTipListCtrl)
    protected:
    virtual void PreSubclassWindow();
    virtual int OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CCellToolTipListCtrl(); // Generated message map functions
    protected:
    int CellRectFromPoint(CPoint & point, CRect &rect, int &col) const;
    //{{AFX_MSG(CCellToolTipListCtrl)
    BOOL OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_CELLTOOLTIPLISTCTRL_H__D0C6B2B8_452A_42CE_B8ED_8650F808E941__INCLUDED_)// CellToolTipListCtrl.cpp : implementation file
    //#include "stdafx.h"
    #include "CellToolTipListCtrl.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CCellToolTipListCtrlCCellToolTipListCtrl::CCellToolTipListCtrl()
    {
    }CCellToolTipListCtrl::~CCellToolTipListCtrl()
    {
    }
    BEGIN_MESSAGE_MAP(CCellToolTipListCtrl, CListCtrl)
    //{{AFX_MSG_MAP(CCellToolTipListCtrl)
    ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
    ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CCellToolTipListCtrl message handlersvoid CCellToolTipListCtrl::PreSubclassWindow() 
    {
    CListCtrl::PreSubclassWindow();
    // Add initialization code
    EnableToolTips(TRUE);
    }int CCellToolTipListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
    {
    int row, col;
    CRect rect;
    row = CellRectFromPoint(point, rect, col );
    TRACE("%d, %d", row, col);
    if ( row == -1 ) 
    return -1; pTI->hwnd = m_hWnd;
    pTI->uId = (UINT)((row<<10)+(col&0x3ff)+1);
    pTI->lpszText = LPSTR_TEXTCALLBACK; pTI->rect = rect; return pTI->uId;
    }// CellRectFromPoint - Determine the row, col and bounding rect of a cell
    // Returns - row index on success, -1 otherwise
    // point - point to be tested.
    // cellrect - to hold the bounding rect
    // col - to hold the column index
    int CCellToolTipListCtrl::CellRectFromPoint(CPoint & point, CRect &rect, int &col) const
    {
    // Make sure that the ListView is in LVS_REPORT
    if(!(GetStyle() & LVS_REPORT)) return -1;
    CListCtrl *pList = (CListCtrl*)this;
    LVHITTESTINFO hi;
    hi.pt = point;
    pList->SubItemHitTest(&hi);
    if(hi.iItem == -1) return -1;
    col = hi.iSubItem;
    CRect rectHeader;
    pList->GetHeaderCtrl()->GetItemRect(col, &rectHeader);
    pList->GetItemRect(hi.iItem, &rect, LVIR_BOUNDS);
    int x = rect.left;
    rect.left = rectHeader.left + x, rect.right = rectHeader.right + x;
    return hi.iItem;
    }BOOL CCellToolTipListCtrl::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
    {
    // need to handle both ANSI and UNICODE versions of the message
    TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
    TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
    CString strTipText;
    UINT nID = pNMHDR->idFrom; if( nID == 0 )    // Notification in NT from automatically
    return FALSE;    // created tooltip int row = ((nID-1) >> 10) & 0x3fffff ;
    int col = (nID-1) & 0x3ff;
    strTipText = GetItemText( row, col );#ifndef _UNICODE
    if (pNMHDR->code == TTN_NEEDTEXTA)
    lstrcpyn(pTTTA->szText, strTipText, 80);
    else
    _mbstowcsz(pTTTW->szText, strTipText, 80);
    #else
    if (pNMHDR->code == TTN_NEEDTEXTA)
    _wcstombsz(pTTTA->szText, strTipText, 80);
    else
    lstrcpyn(pTTTW->szText, strTipText, 80);
    #endif
    *pResult = 0; return TRUE;    // message was handled
    }
      

  3.   

    在解决问题前不要轻易评论问题的难易
    这个控件中显示的tooltip和item的text相同,再改写一下即可