绍:CPPToolTip是一个非常棒的工具提示实现,它支持HTML-lite语句、CSS样式表、菜单、工具条、淡入淡出、超链接、动画、表格等等超强功能。 正文:
CPPToolTip是一个非常棒的工具提示实现,它支持HTML-lite语句、CSS样式表、菜单、工具条、淡入淡出、超链接、动画、表格等等超强功能。
一、使用CPPToolTip的第一步:文件的引用
文件
|
描述
|
PPTooltip.h PPTooltip.cpp |
CPPTooltip 类 |
PPHtmlDrawer.h PPHtmlDrawer.cpp |
CPPHtmlDrawer类. 在tooltip里画出HTML字符串。 |
PPDrawManager.h |
CPPDrawManager类是一组图形处理方法集 |
CeXDib.h CeXDib.cpp |
CCeXDib类,感谢Davide Pizzolato 和 Davide Calabro的提供. 这个类实现了背景特效. |
如果需要使用背景特效,需要定义USE_SHADE:
在 PPDrawManager.h 中 #define USE_SHADE
二、CPPToolTip的基本使用方法:创建CPPToolTip对象
1
|
CPPToolTip m_tooltip; |
然后创建窗口,对于对话框程序,可以在OnInitDialog中
1
2
|
CDialog::OnInitDialog(); m_tooltip.Create( this );
|
然后可以调用AddTool为其它控件注册工具提示,例如:
1
|
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON1), _T( "IDC_BUTTON1控件的工具提示" ));
|
可以为某个区域添加工具提示,例如:
1
|
m_tooltip.AddTool( this , _T( "方框中的Tooltip" ), CRect (100, 100, 200, 200));
|
另外,你需要在PreTranslateMessage中用RelayEvent将鼠标消息传递到工具提示控件中。
1
2
3
4
|
BOOL ... ::PreTranslateMessage(MSG* pMsg)
{ m_tooltip.RelayEvent(pMsg);
} |
1
|
CPPToolTip m_tooltip; |
1
2
3
4
5
6
7
8
9
|
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{ ...
m_tooltip.Create( this );
//为工具条添加工具提示
m_tooltip.AddToolBar(&m_wndToolBar);
return 0;
} |
1
2
3
4
|
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{ m_tooltip.RelayEvent(pMsg);
} |
1
|
CPPToolTip m_tooltip; |
1
|
m_tooltip.Create( this );
|
1
|
#define PPTOOLTIP_USE_MENU |
1
2
3
4
5
6
7
8
9
10
|
void CMainFrame::OnMenuSelect( UINT nItemID, UINT nFlags, HMENU hSubMenu)
{ m_tooltip.OnMenuSelect(nItemID, nFlags, hSubMenu);
CFrameWnd::OnMenuSelect(nItemID, nFlags, hSubMenu);
} void CMainFrame::OnEnterIdle( UINT nWhy, CWnd* pWho)
{ m_tooltip.OnEnterIdle(nWhy, pWho);
} |
1
2
3
4
|
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{ m_tooltip.RelayEvent(pMsg);
} |