Click to See Complete Forum and Search --> : Accessing Main Dialog within a Thread


Andrew Truckle
April 7th, 1999, 02:21 AM
I have a Main Dialog with several data members.

The situation is that I have a popup progress dialog with a cancel button and a worker thread performing the conversion.

I need to get this worker thread to read some of the data members of the overall main dialog window.

What is the simplest way of doing this?

Karl
April 7th, 1999, 07:54 AM
You may share them with the structure used with the worker thread, and protect access with a mutex for example;
An other way may be to share only the handle of your main dialog, and use CWnd::FromHandle to get a pointer on it.

HTH.

K.

Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.

Andrew Truckle
April 8th, 1999, 01:56 AM
Hi Karl

I've ended up using 2 CEvents to check for start and stopping.
The function which calls AfxBeginThread also sets a global pointer:

m_MainWnd = (CDxfRenDlg *)AfxGenMainWnd();

m_MainWnd is declared at the top of the file as:

CDxfRenDlg *m_MainWnd;

I've tested it out and it all seems to work.

Karl
April 8th, 1999, 03:04 AM
Yes, I think you're right; I've seen this in the doc:

"CWinThread::m_pMainWnd (value returned by AfxGetMainWnd when the app is not an OLE server)
Remarks:
Use this data member to store a pointer to your thread's main window object. ...In a worker thread, the value of this data member is inherited from its parent thread.

Thanks for the precision.

K.


Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.