怎样在vs2005/wtl环境使用tooltip
一个button类里面包含一个tooltip(CTooltipCtrl tooltip)
button类从CMessagefilter派生,并处理pretranlatemessage函数
如下:
BOOL PreTranslateMessage(MSG *pMsg)
{
tooltip.RelayEvent(pMsg);
return false;
}
然后映射WM_CREATE, WM_DESTROY消息
如下处理
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->AddMessageFilter(this);
bHandled = FALSE;
return 0;
}
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->RemoveMessageFilter(this);
bHandled = FALSE;
return 0;
}
同时默认消息给基类处理,加上一个CHAIN_MSG_MAP宏
1 当一开始建立工程时不选择Add Common Controls Manifest时,tooltip只有多字节字符集时有效,unicode字符集无效
2 当一开始建立工程时选择Add Common Controls Manifest时,tooltip有效,但如果把stdafx.h中如下一段代码去掉
#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_IA64
#pragma comment(linker, “/manifestdependency:\”type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′ processorArchitecture=’ia64′ 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
则情况同1
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利