CMDIChildWnd in new thread
-
When trying to create CMDIChildWnd in a worker thread I get an ASSERT fails in winmdi.cpp: if (pParentWnd == NULL) { CWinThread *pThread = AfxGetThread(); ASSERT(pThread); CWnd* pMainWnd = pThread->m_pMainWnd; ASSERT(pMainWnd != NULL); ASSERT_KINDOF(CMDIFrameWnd, pMainWnd);//****this line fails pParentWnd = (CMDIFrameWnd*)pMainWnd; } S I guess the parent window is not being set correctly. How can this be set?
-
When trying to create CMDIChildWnd in a worker thread I get an ASSERT fails in winmdi.cpp: if (pParentWnd == NULL) { CWinThread *pThread = AfxGetThread(); ASSERT(pThread); CWnd* pMainWnd = pThread->m_pMainWnd; ASSERT(pMainWnd != NULL); ASSERT_KINDOF(CMDIFrameWnd, pMainWnd);//****this line fails pParentWnd = (CMDIFrameWnd*)pMainWnd; } S I guess the parent window is not being set correctly. How can this be set?
You *have* to create the child window in the same thread its parent was created on. My usual rule is to keep *all* windowing operations within one thread. If you need to create a window in response to an event in a worker thread, post a message across from the worker thread to the main UI thread (posting messages is allowed from worker threads to the UI thread).