ToolTip:TreeCtrl如何不同的item显示不同的说明
解决方案 »
- 又是一年高考时,不知道又有多少童鞋,不如IT这条不归路...
- "消息反射"的概念是Win32API就有的,还是MFC设计出来的?
- 请大家指点我的编程生涯
- 对话框相对于屏幕坐标的问题。
- [高分求解]DLL中使用了CStringArray全局变量的问题
- 计时计数问题,SetTimer,GetTickCount,请进来看看
- 如何用程序取得系统中串口数量?及串口名?
- 请问哪儿有CD_Rom 的UDF文件格式的中文说明
- 讨论一个程序的框架
- 建好一个MFC工程,想实现多国语言,两种方案如何选择?
- papaya_stone(^_^)shentong(^_^) 谢谢你给我发的程序。请进来接分。^_^
- CButton如何得到操作的句柄?
经过改写整理后的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
}
这个控件中显示的tooltip和item的text相同,再改写一下即可