Solved

Progress Bar in a Dialog based application

Posted on 2000-03-08
4
352 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 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