I have a main control in which I have a loop which processes video
frames. To be able to see the results in real time, I created a dialog
in another thread which displays the data as they become available (the
main thread populates a global array, and the second thread picks the
last element and displays it.)
I need to access some functions (e.g. change settings of video
aquisition) in the main thread from within the second thread while the
loop in the main thread is running. I know I have to use messages to do
that, but SendMessage needs a pointer to the main window, and I can't
pass a CWnd * to the secondary thread.
So, how do I call a main thread function from a secondary thread?
Here's a sketch of what I have now:
//in main control:
pThread = (CUIThread*)AfxBeginThread(RUNTIME_CLASS(CUIThread));
pThread->m_pMainWnd = FromHandle(this->m_hWnd);//this does not work
//in UIThread class:
CUIThread::InitInstance()
{
CWnd * cwnd = m_pMainWnd;
m_plot = new Plot_dialog(cwnd);
return TRUE;
}
//in Plot_dialog:
Plot_dialog::Plot_dialog(CWnd* pParent) {}
Plot_dialog::UpdateSetting() {
pParent->SendMessage(WM_PLOT_TO_MAIN, 0, (LPARAM) &CCM);
}