VC中给树形控件的图标加上工具提示
2008-11-13 19:32:33 来源:WEB开发网类声明中的代码如下所示:
// Overrides
// ClassWizard generated
virtual function overrides
//{{AFX_VIRTUAL(CTreeCtrlX)
protected:
…
virtual int OnToolHitTest
( CPoint point, TOOLINFO* pTI ) const;
//}}AFX_VIRTUAL
实现代码如下所示:
int CTreeCtrlX::OnToolHitTest
(CPoint point, TOOLINFO * pTI) const
{
RECT rect;
UINT nFlags;
HTREEITEM hitem = HitTest( point, &nFlags );
if( nFlags & TVHT_ONITEMICON )
{
CImageList *pImg = GetImageList( TVSIL_NORMAL );
IMAGEINFO imageinfo;
pImg- >GetImageInfo( 0, &imageinfo );
GetItemRect( hitem, &rect, TRUE );
rect.right = rect.left - 2;
rect.left -= (imageinfo.rcImage.right + 2);
pTI- >hwnd = m_hWnd;
pTI- >uId = (UINT)hitem;
pTI- >lpszText = LPSTR_TEXTCALLBACK;
pTI- >rect = rect;
return pTI- >uId;
}
else if( nFlags & TVHT_ONITEMSTATEICON )
{
CImageList *pImg = GetImageList( TVSIL_NORMAL );
IMAGEINFO imageinfo;
pImg- >GetImageInfo( 0, &imageinfo );
GetItemRect( hitem, &rect, TRUE );
rect.right = rect.left -
(imageinfo.rcImage.right + 2);
pImg = GetImageList( TVSIL_STATE );
rect.left = rect.right - imageinfo.rcImage.right ;
pTI- >hwnd = m_hWnd;
pTI- >uId = (UINT)hitem;
pTI- >lpszText = LPSTR_TEXTCALLBACK;
pTI- >rect = rect;
// 返回与节点图标不同的值
return pTI- >uId*2;
}
return -1;
}
更多精彩
赞助商链接