2nd thread to update modeless dialog?

I want to use a second thread to update an icon in a modeless dialog while the main application thread initializes data.  I want the 2nd thread to set a timer, and every 250ms update an icon in the modeless dialog.  Can someone provide an example?
dmetzlerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

altenaCommented:
Wrong way around...

You really want the main thread to be resposible for the UI
and the second(worker) thread to do the work.

That way you can use the good old windows timer for your
"every 250 ms update".
0
dmetzlerAuthor Commented:
Okay - but how is this done?

Thanks,

Don
0
piano_boxerCommented:

Add a WM_CREATE handler to the dialog and insert this line to it:
SetTimer(1, 250, NULL);


Add a WM_TIMER handler. This function will now be called every ~250 ms.

Add WM_DESTROY handler and insert this:
KillTimer(1);
0
dmetzlerAuthor Commented:
Okay - here's more specifics:

1) I have a modal dialog MFC program (main window is the dialog).
2) In the OnInitDialog() handler I am initializing UI items for the main dialog window.  This process is lengthy, so I open a modeless dialog I use to display the status while the main dialog initializes.
3) I need to update the modeless dialog's UI while the main dialog is initializing.

I know this seems backwards, but there has to be a way to pass the CStatic handle for the icon to the modeless dialog and have it use a timer/thread to update itself while the main dialog initializes.  I cannot use a SetTimer() in either dialog as they are part of the same main application thread.  I would need to create a secondary thread for the modless status dialog.

Sorry for the confusion.

Thanks,

Don

0
RONSLOWCommented:
Look at the MTMDI sample.

Basically create a CWinThread derived class whose InitInstance creates your modeless dialog and sets m_pMainWnd to it.

See the sample code for how to wire it all up.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.