当前位置:C++技术网 > 资讯 > CToolTipCtrl类实现提示框提示

CToolTipCtrl类实现提示框提示

更新时间:2016-01-20 19:41:50浏览次数:1+次

鼠标移动时的背景透明文字不透明的实时提示框效果MFC实现》实现的是自定义的提示框,但是不仅仅在控件上显示。自我感觉这个比封装的提示框类更好。

定义一个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