Solved

indeterminate progress bars

Posted on 2002-07-19
9
611 Views
Last Modified: 2013-11-20
Hi ,
 Does anyone know on how to create indeterminate progress bars in a dialog. I have this big dialog function which will load another DLL and execute functions within it. I need to show in my dialog that a processing is going on. I tried creating a thread and updating the progress control but no luck. It looks like the message pump is blocked until the dialog function is completed. Is there any other way I could implement this

Thanks
Saravana
0
Comment
Question by:vsaravana
  • 4
  • 2
9 Comments
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
Using multi-threading is the way to go. I don't know what you did, but you must have made a mistake. Did you create the thread to do the actual work? I assume you created a thread to do the updating of the progress bar. In that case the dialog message-handler isn't called until the function doing the calculations has returned.
0
 

Author Comment

by:vsaravana
Comment Utility
You are correct, I did create the thread for the progress update. It's difficult as per the previous implementation to move tons of code into a thread.
Is there any other option..??

0
 
LVL 8

Accepted Solution

by:
fl0yd earned 100 total points
Comment Utility
You could use a CWinThread-function (PumpMessage) that is not really well documented:

void DoEvents() {

    MSG msg = { 0 };
    HWND hwnd = AfxGetMainWnd->m_hWnd;
    while( ::PeekMessage( &msg, hwnd, 0, 0, PM_NOREMOVE ) )
        AfxGetApp()->PumpMessage();
}

Call this function whenever you need to respond to messages. So your code would look like this:

void ThisFunctionTakesForEver() {

    // do some code here
    DoEvents();
    // do some more code...
    DoEvents();
    // and so on...
}

If you use this you won't have to use multithread, which is a very complex field of programming.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
ooooops, there was a mistake. The right way to go:

    HWND hwnd = AfxGetMainWnd()->m_hWnd;
0
 
LVL 1

Expert Comment

by:jemax
Comment Utility
Hi,

you could use CWnd::UpdateWindow it bypasses message queue, so your progress bar will be updated.

HTH,
jemax
0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
UpdateWindow sends a WM_PAINT message if the update region isn't empty -- what good is it if those aren't handled?
0
 
LVL 1

Expert Comment

by:jemax
Comment Utility
Hi,

forgive me, my stupid comment. I forgot that is not possible to SendMessage into wnd thread from another thread, it would cause to deadlock.

Sorry.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

6 Experts available now in Live!

Get 1:1 Help Now