Waiting for Dialog to update in a Nnew Thread



I have a main thread that controls all of the UI and calculations. I want
another thread to maintain a progress/log, and also to show a Cancel button
to interrupt long calculations in the main thread, the main window is hidden
during these calculations but the progress box is vizible.

I want a list control in the progress box to say what stage the calculations
have reached.

I have got the thing working by running the processing functions in new
threads but the code is messy, and hard to maintain. So I want to do
something like this:-

// this is a function from my dialog class
void CProgress::AddString(char *s)
{
m_list.AddString(s);
m_list.SetTopIndex(m_list.GetCount()-1);
UpdateWindow();
}

// This function is in the same class as the instance of the dialog above,
the thread class
//{{AFX_MSG_MAP(CProgressThread)
ON_THREAD_MESSAGE(WM_PROGRESS_ADD,Add)
void CProgressThread::Add(WPARAM w,LPARAM l)
{
HANDLE event;
event=OpenEvent(EVENT_ALL_ACCESS,true,"AddEvent");
progress.AddString((char*)l); // ***
SetEvent(event);
CloseHandle(event);
}

// This functuion is in the main processing class, I want it to wait until
the text appears in the dialog
char* t[128];
void CCombineDoc::AddString(CString s)
{
if(s.GetLength()>127) s=s.Left(127);
strcpy(t,s);
HANDLE event;
event=CreateEvent(0,true,false,"AddEvent");
progress->PostThreadMessage(WM_PROGRESS_ADD,0,(long)t);
WaitForSingleObject(event,INFINITE);
CloseHandle(event);
}

But it locks up. If I comment out the line marked // *** the Wait works
properly, so the problem is something to do with manipulating the dialog
controls.

Any suggestions?

Alan


.