定义一个CToolTipCtrl类的对象m_tooltip,在OnInitDialog中写代码:
m_tooltip.Create(this,TTS_ALWAYSTIP);
m_tooltip.AddTool(GetDlgItem(IDC_BTN_TIP),L"测试");
m_tooltip.SetDelayTime(200);
//m_tooltip.SetMaxTipWidth(50);
m_tooltip.SetMargin(CRect(10,10,30,30));
m_tooltip.Popup();
重载PreTranslateMessage函数:
BOOL C气泡提示Dlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
/*if(pMsg->message==WM_LBUTTONDOWN || pMsg->message==WM_LBUTTONUP
||pMsg->message==WM_MOUSEMOVE)*/
if(m_tooltip.m_hWnd!=NULL)
{
m_tooltip.RelayEvent(pMsg);
}
return CDialogEx::PreTranslateMessage(pMsg);
}
注释掉stdafx.h里的一段代码,才能实现提示框颜色的设置:
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif