Solved

download progress (threads)

Posted on 2003-10-23
6
336 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
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!

 
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: 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.

Question has a verified solution.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

739 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