本文来源:http://blog.163.com/adslxk@126/blog/static/100610671201041434131337/
一个vc6的项目放到vc8下重新编译 这里死活过不去 查了些资料无果 后来翻到一句老外的回答
If AfxGetMainWnd is called from the application’s primary thread, it returns the application’s main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call.
大概意思就是说在子线程里面调用AfxGetMainWnd()返回的是和当前线程相关联的窗体句柄而不是当前程序的主窗体句柄。 不知道这是不是vc8的一个改变,也没时间去细查。
解决方法1:
CWnd* m_pCWnd = NULL;
在OnInitDialog里 m_pCWnd = AfxGetMainWnd();
解决方法2:
调用AfxGetMainWnd()的地方替换成AfxGetApp()->m_pMainWnd
编译后运行问题解决
本文解决了一个VC6项目在VC8环境下编译时遇到的问题:AfxGetMainWnd()在子线程中返回错误的窗口句柄。提供了两种解决方案:一是在OnInitDialog中保存主窗口句柄;二是直接通过AfxGetApp()->m_pMainWnd获取。
282

被折叠的 条评论
为什么被折叠?



