Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

2nd thread to update modeless dialog?

Posted on 1998-04-19
5
Medium Priority
?
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 600 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 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