Modeless Dialog with Progress Bar 
Author Message
 Modeless Dialog with Progress Bar

I have written an application which puts up a modal dialog
box and prompts the user for some input information.  I
then create a modeless dialog box with a progress bar.  I
then start running some code which can take a long time
to run.  This code sends progress data to the modeless dialog
box to update the progress bar.  This all works fine but
I would like to add an abort button in the modeless dialog.
I have tried this I can't get the abort button to work.  Does
anyone know how to get this to work?  Below is an example of
how I put the application together.

One other thing I noticed is I get the hour glass if I do
not call the modal dialog before calling DriverMain.

Thanks.

  #include "CDriver.h"
  #include "CDriverDlg.h"

  #include "utility.h"

  CDriverApp gcDriverApp;
  CDriverApp *gcpApplication;

  BEGIN_MESSAGE_MAP(CDriverApp, CWinApp)
    ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  END_MESSAGE_MAP()

  CDriverApp::CDriverApp()
  {
    gcpApplication = this;
  }

  BOOL CDriverApp::InitInstance()
  {
    CDriverDlg cDriverDlg;

    cDriverDlg.m_strStartTime = m_strStartTime;
    cDriverDlg.m_strEndTime   = m_strEndTime  ;
    cDriverDlg.m_strFrequency = m_strFrequency;

    if (IDOK == cDriverDlg.DoModal())
    {
      m_strStartTime = cDriverDlg.m_strStartTime;
      m_strEndTime   = cDriverDlg.m_strEndTime  ;
      m_strFrequency = cDriverDlg.m_strFrequency;

      DriverMain();
    }

    return FALSE;
  }

  BOOL CDriverApp::DriverMain()
  {
    CExecuteDlg cDlg;
    cDlg.Create(IDD_EXECUTE);
    cDlg.UpdateWindow();

    for (m_cClock.m_iTimeCounter  = m_cClock.m_iStartCounter;
         m_cClock.m_iTimeCounter <= m_cClock.m_iEndCounter  ;
         m_cClock.m_iTimeCounter++)
    {
      DO SOME STUFF HERE

      INT iTimeRatio = INT(100.0F * (m_fTime / m_fEndTime));

      SendMessage(cDlg.m_hWnd, WM_COMMAND, IDC_UPDATE_TIME,
LPARAM(iTimeRatio));
    }

    cDlg.DestroyWindow();

    return FALSE;
  }

--
Remove the PPP for the correct email address.



Sun, 16 Sep 2001 03:00:00 GMT  
 Modeless Dialog with Progress Bar
You could try setting a global abort flag, testing it after each call to
SendMessage.

Johan Rosengren
Responsable Informatique
PACTA S.A.



Mon, 17 Sep 2001 03:00:00 GMT  
 Modeless Dialog with Progress Bar
I guess I should have stated the Abort button never gets serviced.  That
is the problem.
Quote:

> I have written an application which puts up a modal dialog
> box and prompts the user for some input information.  I
> ...



Mon, 17 Sep 2001 03:00:00 GMT  
 Modeless Dialog with Progress Bar

Neal,

I think that the problem is that your loop is keeping you from processing
any messages (like button clicks).  What you want to do either start a
worker thread to do the processing or check the message pump from time to
time to see if the user has clicked on the abort button or tried to do
something else...  See the code below.

Hope this helps,
Chris

void CheckMessagePump()
{
    MSG msg;

    // Handle all of the messages on the queue.
    while( ::PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE) )
    {
        ::TranslateMessage(&msg);
        ::DispatchMessage(&msg);
    }

Quote:
} // end CheckMessagePump

  BOOL CDriverApp::DriverMain()
  {
    CExecuteDlg cDlg;
    cDlg.Create(IDD_EXECUTE);
    cDlg.UpdateWindow();

    for (m_cClock.m_iTimeCounter  = m_cClock.m_iStartCounter;
         m_cClock.m_iTimeCounter <= m_cClock.m_iEndCounter  ;
         m_cClock.m_iTimeCounter++)
    {
      DO SOME STUFF HERE

      INT iTimeRatio = INT(100.0F * (m_fTime / m_fEndTime));

      SendMessage(cDlg.m_hWnd, WM_COMMAND, IDC_UPDATE_TIME,
LPARAM(iTimeRatio));

        // Now check the message pump to handle any messages...
        CheckMessagePump();
    }

    cDlg.DestroyWindow();

    return FALSE;
  }

Quote:

> I guess I should have stated the Abort button never gets serviced.  That
> is the problem.


> > I have written an application which puts up a modal dialog
> > box and prompts the user for some input information.  I
> > ...



Mon, 17 Sep 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Modeless Dialog w/progress bar?????????

2. Showing a modeless progress dialog while opening document with MFC

3. Progress bar not showing visual progress

4. Showing file loading/saving progress in progress bar?

5. ATL dialog & progress bar

6. update progress bar in a popup dialog

7. Progress Bar only shows on dialog

8. Displaying progress bar right after dialog is on screen

9. Progress bar in dialog, right after display

10. Need feedback from thread to dialog and progress bar

11. progress bar on a status bar

12. progress bar on a status bar

 

 
Powered by phpBB® Forum Software