您的位置:首页 > 其它

win32 API创建tooltip的版本不匹配问题解决方法

2010-08-08 10:26 579 查看
    在visual studio 2005以上版本中使用API创建tootip,创建后发送TTM_ADDTOOL等消息会失败,原因是加载的commctrl dll版本不匹配,解决方法如下:

 

1 在stdafx.h文件中把 #define _WIN32_WINNT 0x0501 改为 #define _WIN32_WINNT 0x0500

 

2 在#include "commctrl.h" #pragma comment(lib, "comctl32.lib") 之前加上如下代码:

#if _WIN32_WINNT>0x0500

#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

#endif

 

3 在填充TOOLINFO结构时改变cbSize的大小,如下:

TOOLINFO ti;
memset(&ti, 0, sizeof(TOOLINFO));

#if _WIN32_WINNT>0x0500
  ti.cbSize = sizeof(TOOLINFO)-sizeof(void*);
#else
  ti.cbSize = sizeof(TOOLINFO);
#endif

原因是因为_WIN32_WINNT 大于0x0500的时候,TOOLINFO结构体多了一个LPARAM lParam的定义,导致sizeof(TOOLINFO)和旧版本不匹配。

 

推荐使用第3种方法,因为前两种方法修改了整个commctrl dll版本号,导致整个系统用到的都是会较低版本的commctrl dll

 

示例代码如下:

HWND hWindow = ::CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,   WS_POPUP|TTS_NOPREFIX|TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,   NULL, (HMENU)0, NULL, NULL);

 

TOOLINFO ti;
memset(&ti, 0, sizeof(TOOLINFO));

#if _WIN32_WINNT>0x0500
  ti.cbSize = sizeof(TOOLINFO)-sizeof(void*);
#else
  ti.cbSize = sizeof(TOOLINFO);
#endif

。。。//其他数据填充

::SendMessage(hWindow, TTM_ADDTOOL, 0, &ti);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  api linker null tts dll class
相关文章推荐