ruff_ryder
asked on
Running a CDialog in a separate Thread
My app is an SDI. I Have a class that serves as a Singleton and it contains a meethod that should start a thread and display a modeless CDialog derived class within that thread. The reason I do this is so that when the Dialog is displayed, the user can still do something else in the app.
Now, my major prob is that I am getting an ASSERT failure during the CDialog::Create(). I've posted the relevant pieces of code below:
CFrameWndDerived::OnStart( )
{
// Create Progress Dialog and Display it
BOOL ret = m_configProgress.Create();
if(!ret) //Create failed.
AfxMessageBox("Error creating Processing Dialog");
m_configProgress.ShowWindo w(SW_SHOW) ;
}
CFrameWndDerived::OnDone()
{
m_configProgress.ShowWindo w(SW_HIDE) ;
m_configProgress.DestroyWi ndow();
}
The m_configProgress variable is a member of CFrameWnd class. Any help would be appreciated as I've been on tis for a while now!
Now, my major prob is that I am getting an ASSERT failure during the CDialog::Create(). I've posted the relevant pieces of code below:
CFrameWndDerived::OnStart(
{
// Create Progress Dialog and Display it
BOOL ret = m_configProgress.Create();
if(!ret) //Create failed.
AfxMessageBox("Error creating Processing Dialog");
m_configProgress.ShowWindo
}
CFrameWndDerived::OnDone()
{
m_configProgress.ShowWindo
m_configProgress.DestroyWi
}
The m_configProgress variable is a member of CFrameWnd class. Any help would be appreciated as I've been on tis for a while now!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx dude! worked nicely!!
ASKER
Dan I'm having another problem now. I split off a worker thread to do some work but I need the main thread to update the Modeless Dialog. I looked on your code:
// start the operation
BOOL fDone= FALSE;
while( !fDone ) {
MSG rMsg;
while ( ::PeekMessage( &rMsg, 0, 0,0, PM_NOREMOVE) ){
AfxGetApp()->PumpMessage() ;
}
// do some more work, set fDone= TRUE when done
}
My question is, if im doingthe work in the Worker Thread, how do i access the main thread so that I can call the ::PeekMessage
// start the operation
BOOL fDone= FALSE;
while( !fDone ) {
MSG rMsg;
while ( ::PeekMessage( &rMsg, 0, 0,0, PM_NOREMOVE) ){
AfxGetApp()->PumpMessage()
}
// do some more work, set fDone= TRUE when done
}
My question is, if im doingthe work in the Worker Thread, how do i access the main thread so that I can call the ::PeekMessage
ASKER
CWnd::AssertValid() line 884 + 27 bytes
CFrameWnd::AssertValid() line 2123
CMainFrame::AssertValid() line 92
AfxAssertValidObject(const
CWnd::CreateDlgIndirect(co
CDialog::CreateIndirect(co
CDialog::CreateIndirect(vo
CDialog::Create(const char * 0x0000006b, CWnd * 0x00000000 {CWnd hWnd=???}) line 182 + 20 bytes
CDialog::Create(unsigned int 107, CWnd * 0x00000000 {CWnd hWnd=???}) line 543 + 29 bytes
CXMLToolProgressDlg::Creat
CXMLToolApp::OnConfigurati
EvalManager::BeginProcessi
EvalManager::RunInternal()
RunInternalThreadProc(void
_AfxThreadEntry(void * 0x0012f938) line 112 + 13 bytes
_threadstartex(void * 0x007e24c0) line 212 + 13 bytes
KERNEL32! 77e92ca8()
and here's the line of wincore.cpp [Line 884] where the error occurs:
ASSERT((CWnd*)p == this); // must be us
The "this" variable looks like this in the variable watch window:
this 0x007b4b98 {CMainFrame hWnd=???}