添加成员变量:
CToolTipCtrl m_Tip;
在OnCreate函数(对话框程序是OnInitDialog)中添加代码:
m_Tip.Create(this,TTS_ALWAYSTIP);
m_Tip.AddTool(&m_Btn1,"abc");
其中m_Btn1是一个按钮自动关联的成员变量,鼠标移动到此按钮上就会显示hint。
对话框程序很简单,直接重载BOOL CxxxDlg::PreTranslateMessage(MSG* pMsg),在此函数中添加代码:
if(NULL != m_Tip.m_hWnd)
m_Tip.RelayEvent(pMsg);
ActiveX需要利用HOOK实现。
在OnCreate函数中添加:
g_hHook = SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,NULL,GetCurrentThreadId());
添加HOOK回调函数:
LRESULT CALLBACK GetMsgProc(int nCode,WPARAM wParam,LPARAM lParam)
{
TRACE("MouseProc/n");
MSG* pMsg = (MSG*)lParam;
if((NULL != This) && (NULL != This->m_Tip.m_hWnd))
{
TRACE("RelayEvent/n");
This->m_Tip.RelayEvent(pMsg);
}
return 0;
}