Solved

2nd thread to update modeless dialog?

Posted on 1998-04-19
5
264 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
Comment Utility
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
Comment Utility
Okay - but how is this done?

Thanks,

Don
0
 
LVL 4

Expert Comment

by:piano_boxer
Comment Utility

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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 88
List out all word 7 219
java ^ examples 8 57
unix example issues 18 44
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

11 Experts available now in Live!

Get 1:1 Help Now