progress bar is not working properly while minimize the application.

Hello all,

I am using Microsoft visual C++ 8 for development. In this i am loading 72 images into application.

I am trying to show a progress bar while my process is going on.i.e loading images.., while this progress is under process minimize the current application and maximize the progress bar is not working properly that means application shows blank area.

Please help me to solve this problem.

Thanks in Advance.
Last edited on
Can you post the code?
I think I know where your problem is.

For this you need to understand multi-threading and how it effects your program.
Without knowing your code and from what you posted I take it that you are loading the images in your main or UI thread. visual C++ will make a new thread for you application to run in, this means your code and the UI will run in this thread. Your UI is updated when the program is not doing anything, this is a complicated but very efficient system build in to windows that tests if your interface needs to be updated (redrawn to the screen). But a thread (any thread) can only do one thing at a time. Your code has priority over lower functions like updating so when you start loading the images all resource of your thread go to doing so, and the UI will 'frees' and not update since something else (the loading function) is using it. To fix this you need to run your loading function in a new thread and make callbacks to the UI or main thread updating the progressbar. This is not so simple if you don't know multi-threading and needs invocations from the UI back to your thread to avoid that the UI uses data that is already outdated or still being used by the other thread.

To make it simpler to do this .net has a build in class that handles all this threading stuff you don't want to be thinking of when doing something as simple as a loading screen. This is called a BackgroundWorker, This allows you to simply execute a function in a different thread and has a build-in event to make callbacks to update your progressbar or any outer UI element that needs updating.

Have a look at this:
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
Hello Null..

I am posting code snippets to implementing progress bar and updating progress bar.

Progress Bar Implementation:

I take a new dialog, created a new class for that and placed a progress bar control on dialog.

The following code was inserted in OnInitDialog() in progress class.

m_Progress.SetWindowPos(&wndTop,10,1,wh-150,40,SWP_SHOWWINDOW);

Here m_Progress is a variable for progress bar control.

In loading images function i am inserted the following code to show progress bar.

m_Dlg = new ProgDlg(this);
m_Dlg->Create();

Here m_Dlg is object for pogress bar class.

ProgressBar updating:

For this, i wrote one function in progress bar class and set image index to that function. call this function in for loop in loading images function.

m_Progress.SetPos(count); this code is used to update progress bar.

And I got some information in Google. Implement BackGroundWorker threads to solve this problem.

Please help me to implement BackGroundWorker threads in VC++.
Hello Raggers,

Thanks for your reply..

I posted code snippets for my task. I am poor in threads concepts.
BackGroundWorker threads concept is helpful for me, please help me to develop.

What you need to do is run your loading function inside a BackGroundWorker by using the backgroundWorker->DoWork event.
Then need to listen to the backgroundWorker->ProgressChanged event every time this event is raised it will pass a int or a int and object that you'll use to update your progressbar.
This will be raised every time the ProgressChanged(int, object) or ProgressChanged(int) function is called, the int will be your progress (in percentages or whatever you like) and the optional object can be used to pass along more information.
In your loading code you need to call the BackGroundWorker->ProgressChanged(int, object) or BackGroundWorker->ProgressChanged(int) function, this will raise the backgroundWorker->ProgressChanged event for you.

Read the http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx page for more information.
Topic archived. No new replies allowed.