Solved

2nd thread to update modeless dialog?

Posted on 1998-04-19
5
284 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
substring method in java 1 122
method notes when mouse over in eclipse 5 87
ShiftLeft challenge 21 82
Problem to App 4 83
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

810 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