Solved

download progress (threads)

Posted on 2003-10-23
6
333 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 118
ASCII Non-Printable characters/codes and their HTML equivalents 6 143
viewing source code from eclipse 13 110
Message not shown 5 84
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli‚Ķ
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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