• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 685
  • Last Modified:

indeterminate progress bars

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
vsaravana
Asked:
vsaravana
  • 4
  • 2
1 Solution
 
fl0ydCommented:
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
 
vsaravanaAuthor Commented:
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
 
fl0ydCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
fl0ydCommented:
ooooops, there was a mistake. The right way to go:

    HWND hwnd = AfxGetMainWnd()->m_hWnd;
0
 
jemaxCommented:
Hi,

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

HTH,
jemax
0
 
fl0ydCommented:
UpdateWindow sends a WM_PAINT message if the update region isn't empty -- what good is it if those aren't handled?
0
 
jemaxCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now