Solved

download progress (threads)

Posted on 2003-10-23
6
313 Views
Last Modified: 2013-11-20
hi there..

i have a function in my Dialog-based MFC app that checks for updates

void CExDlg::CheckForUpdates()
{
      //...
      //pUpdateDlg is the child dialog has the progress bar

      for (int x = 0; x < num_updatedfiles; x++)
      {
            //function that downloads the updated file
            m_Ftp->GetFile(strFile[x], strFile[x], FALSE, ...);
            pUpdateDlg->m_MyProgressBar.SetPos(x); //<==
      }
}

well problem is =\ the progress bar doesn't move (the whole dialog doesn't refresh) so i'm gonna have to use Threads so the progress bar moves after each file download.

i don't know much about how to use um.. anyone got any ideas?

tried using the ones on CodeProject but i guess i'm just a newbie n dunno how to use them =p
0
Comment
Question by:WilimarLynwood
  • 2
  • 2
  • 2
6 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 9612411
Add function DoEvents:

void CExDlg::DoEvents()
{
    MSG msg;
   
    while ( ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE ) )
    {  
        if ( ::GetMessage(&msg, NULL, 0, 0))
        {
            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
        }
        else
        {
            break;
        }
    }
}

Call it from the loop:

void CExDlg::CheckForUpdates()
{
    //...
    //pUpdateDlg is the child dialog has the progress bar

    for (int x = 0; x < num_updatedfiles; x++)
    {
         //function that downloads the updated file
         m_Ftp->GetFile(strFile[x], strFile[x], FALSE, ...);
         pUpdateDlg->m_MyProgressBar.SetPos(x);

         DoEvents();   // here progress bar is redrawn
    }
}



0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9612470
         pUpdateDlg->m_MyProgressBar.SetPos(x); //<==
          pUpdateDlg->UpdateWindow();   //force it to redraw
0
 
LVL 1

Author Comment

by:WilimarLynwood
ID: 9612482
tried that before, AndyAinscow, didn't work =(

and, not really sure what the DoEvent() function does, AlexFM, but it works GREAT! =p

Thanks both of you =)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 48

Expert Comment

by:AlexFM
ID: 9612546
DoEvents handles all Windows messages in the queue, including WM_PAINT. This is a reason dialog is redrawn. Without DoEvents messages remain in queue and handled only when function CheckForUpdates exits.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9612614
Your right.  I had a look at an older app that had exactly the same probelm with a prgress control.  I forgot I had a fn to do what Alex suggested in it.
0
 
LVL 1

Author Comment

by:WilimarLynwood
ID: 9612622
ah =) i have many stuff that needed calling this function after, this helps alot!, hehe
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 85
bobThere java chalenge 45 91
building a service to accessed via telnet client, want colors ? 4 83
Not needed 13 94
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now