Solved

Progress Bar in a Dialog based application

Posted on 2000-03-08
4
351 Views
Last Modified: 2013-11-20
My application is a dialog based application in VC++ 6.0

On click of a button i am creating a modeless dialog consisting of a static text field,a ProgressBarControl and a cancel button.

From the main dialog i am using a for loop to increment the progress bar and check if the user has pressed the cancel button.

Everything works fine except that the for loop does not seem to release control and the user cannot press the cancel button.
I dont understand why the progress dialog does not reconise any events during the for loop in the main dialog.

below is the code

void CMainDialog::OnClickProgButton()
{
Demo* pDialog;
pDialog = new Demo(this);
BOOL dd=pDialog->Create();
      
pDialog->SetRange(0,50000);
for(int i=0;i<50000;i++)
{
  pDialog->StepIt();
  if(pDialog->IsCancelled())
  {
    MessageBox("Cancelled","Error");
    break;
  }
}
      
pDialog->DestroyWindow();
}
0
Comment
Question by:mickoo
[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
4 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2595618
Hi,

I would suggest to put the code for the updation of the progress bar in the dialog, where it has been put. So as soon as user presses cancel, U can abort it. That seems to be the simple and best way. Whay can't u go for that?

VinExpert
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 100 total points
ID: 2595672
Hi mickoo,

This is because the for-loop blocks the message processing. Such lengthy loops should be avoided to allow the application the handling of messages. You can try one of the following:

- Instead of a for-loop try to do such lengthy calculation either in idle time (see WM_ENTERIDLE and CWinApp::OnIdle()) or in a thread (see AfxBeginThread())

- Inside the loop check message queue for new messages and process them, i.e. like this:

MSG msg;
for(int i=0;i<50000;i++)
{
 if ( i % 100 == 0 )
 {
  // here every 100th loop we check message queue
  while ( ::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  {
   ::DispatchMessage( &msg );
  }
 }
 pDialog->StepIt();
 if(pDialog->IsCancelled())
 {
  MessageBox("Cancelled","Error");
  break;
 }
}


hope that helps,

ZOPPO
0
 
LVL 1

Expert Comment

by:Sadhu
ID: 2595988
0
 

Author Comment

by:mickoo
ID: 2599253
Thanks a lot Zappo

your suggestion worked perfectly
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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