Solved

2nd thread to update modeless dialog?

Posted on 1998-04-19
5
274 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:dmetzler
5 Comments
 
LVL 3

Expert Comment

by:altena
ID: 1300369
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
 

Author Comment

by:dmetzler
ID: 1300370
Okay - but how is this done?

Thanks,

Don
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1300371

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
 

Author Comment

by:dmetzler
ID: 1300372
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
 
LVL 10

Accepted Solution

by:
RONSLOW earned 150 total points
ID: 1300373
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now