AfxGetMainWnd()在线程里使用的问题

AfxGetMainWnd()的使用依赖于线程
具体参加源代码

 1_AFXWIN_INLINE CWnd* AFXAPI AfxGetMainWnd()
 2{ CWinThread* pThread = AfxGetThread();
 3   return pThread != NULL ? pThread->GetMainWnd() : NULL; }

 4
 5//而AfxGetThread获取的是当前线程,而不是主线程!
 6CWinThread* AFXAPI AfxGetThread()
 7{
 8// check for current thread in module thread state
 9AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
10CWinThread* pThread = pState->m_pCurrentWinThread;
11return pThread;
12}

13
所以在非主线程里使用可能会有问题,解决方法,在新创建的线程里使用AfxGetApp()->m_pMainWnd;

posted on 2010-08-26 11:08 Brandon 阅读(895) 评论(0)  编辑 收藏 引用 所属分类: MFC


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年8月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

收藏夹

IT WEB

常用链接

牛人BLOG

学习网站

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜