怎样在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

posted @ 2012-04-09 13:08  特米尼德  阅读(769)  评论(0编辑  收藏  举报