VC中给树形控件的图标加上工具提示
2008-11-13 19:32:33 来源:WEB开发网BOOL CTreeCtrlX::OnToolTipText
( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
{
// 需要处理ANSI和UNICODE两种格式
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
CString strTipText;
UINT nID = pNMHDR- >idFrom;
// 不必处理树自己发出的ToolTip消息
if( nID == (UINT)m_hWnd &&
(( pNMHDR- >code == TTN_NEEDTEXTA &&
pTTTA- >uFlags & TTF_IDISHWND ) ||
( pNMHDR- >code == TTN_NEEDTEXTW &&
pTTTW- >uFlags & TTF_IDISHWND ) ) )
return FALSE;
// 得到鼠标位置
const MSG* pMessage;
CPoint pt;
pMessage = GetCurrentMessage();
ASSERT ( pMessage );
pt = pMessage- >pt;
ScreenToClient( &pt );
UINT nFlags;
HTREEITEM hitem = HitTest( pt, &nFlags );
if( nFlags & TVHT_ONITEMICON )
{
int nImage, nSelImage;
GetItemImage( (HTREEITEM ) nID, nImage, nSelImage );
switch(nImage)
{
case 0:
strTipText = "叉";
break;
case 1:
strTipText = "加号";
break;
case 2:
strTipText = "菱形";
break;
}
}
else
{
if( (GetItemState( (HTREEITEM ) nID,
TVIS_STATEIMAGEMASK ) > >12 ) == 2 )
strTipText.Format( "此节点被选中" );
else
strTipText.Format( "此节点未被选中" );
}
#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; // 消息处理完毕
}
---- 本文程序在Win9x,VC6.0下调试通过。
更多精彩
赞助商链接