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
Solved

download progress (threads)

Posted on 2003-10-23
6
326 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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: 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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

791 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