AfxGetMainWnd()在线程里使用的问题
2010-08-26 11:16
555 查看
AfxGetMainWnd()的使用依赖于线程
具体参加源代码
1
_AFXWIN_INLINE CWnd* AFXAPI AfxGetMainWnd()
2
{ CWinThread* pThread = AfxGetThread();
3
return pThread != NULL ? pThread->GetMainWnd() : NULL; }
4
5
//而AfxGetThread获取的是当前线程,而不是主线程!
6
CWinThread* AFXAPI AfxGetThread()
7
{
8
// check for current thread in module thread state
9
AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
10
CWinThread* pThread = pState->m_pCurrentWinThread;
11
return pThread;
12
}
13
所以在非主线程里使用可能会有问题,解决方法,在新创建的线程里使用AfxGetApp()->m_pMainWnd;
http://www.cppblog.com/maosher/
具体参加源代码
1
_AFXWIN_INLINE CWnd* AFXAPI AfxGetMainWnd()
2
{ CWinThread* pThread = AfxGetThread();
3
return pThread != NULL ? pThread->GetMainWnd() : NULL; }
4
5
//而AfxGetThread获取的是当前线程,而不是主线程!
6
CWinThread* AFXAPI AfxGetThread()
7
{
8
// check for current thread in module thread state
9
AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
10
CWinThread* pThread = pState->m_pCurrentWinThread;
11
return pThread;
12
}
13
所以在非主线程里使用可能会有问题,解决方法,在新创建的线程里使用AfxGetApp()->m_pMainWnd;
http://www.cppblog.com/maosher/
相关文章推荐
- 关于在线程中使用AfxGetMainWnd()出错的问题
- 关于在线程中使用AfxGetMainWnd()出错的问题,终于找到了
- 关于在线程中使用AfxGetMainWnd()出错的问题,终于找到了
- 关于在线程中使用AfxGetMainWnd()出错的问题,终于找到了
- 关于在线程中使用AfxGetMainWnd()出错的问题,终于找到了
- 关于在线程中使用AfxGetMainWnd()出错的问题,终于找到了
- vs2010中,在线程中,调用SendMessage(AfxGetMainWnd()->m_hWnd,...)异常的问题
- afxgetapp->afxmainwnd 与afxgetmainwnd的区别 /线程中调用afxgetmainwnd的问题
- 在线程中执行AfxGetMainWnd()出错的问题
- 在另一个线程中无法用((CMainFrame *)AfxGetMainWnd())的解决方法
- 指定MessageBox所属父窗口(使用AfxGetMainWnd())
- 【多线程与AfxGetMainWnd & 窗口 与 线程 有必然联系吗? & 命名空间】
- 【框架-MFC】MFC 应用程序 AfxGetMainWnd();在子线程中返回null
- (转)使用AfxGetMainWnd函数的一个心得
- 前台线程与后台线程,AfxGetApp->GetMainWnd()与AfxGetMainWnd的不同 (转)
- VC8下多线程环境中AfxGetMainWnd()返回空指针问题及解决方法
- 使用AfxGetMainWnd函数的一个心得
- MFC线程里调用AfxGetMainWnd的陷阱
- 使用AfxGetMainWnd函数的一个心得
- 多线程AfxGetMainWnd问题的解决