Progress bar - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28

Thread: Progress bar

  1. #16
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    I searched these forums for CopyFileEx and I really think there is some help there. Did you look in the CodeGuru articles?
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  2. #17
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by jkw2068
    Not sure what is meant by this. Could you explain please?
    Well...what I want to know (and probably see) is where you actually call the function 'CopyFile()'. You have a modal dialog opened with a progress bar...thus, I am assuming that the function will be called somewhere within this modal dialog...and in order to determine exactly why you are having problems with updating your progress bar...
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

  3. #18
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,206
    Originally posted by Andreas Masur
    Well...what I want to know (and probably see) is where you actually call the function 'CopyFile()'. You have a modal dialog opened with a progress bar...thus, I am assuming that the function will be called somewhere within this modal dialog...and in order to determine exactly why you are having problems with updating your progress bar...
    I believe his problem is that if for example, he has 1mb worth of files to copy and one of the files is 800k he sits for a minute while it copies then gets an 80% jump on his progress bar. He needs to be able to increment the progress bar smoothly, which will require feedback from whatever method he uses to copy the file. CopyFileEx will provide that feedback, or he could write his own copy function pretty easily too. Combine the feedback with a PeekMessage, DispatchMessage call and he'll be there. No need for threads.

  4. #19
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by GCDEF
    I believe his problem is that if for example, he has 1mb worth of files to copy and one of the files is 800k he sits for a minute while it copies then gets an 80% jump on his progress bar. He needs to be able to increment the progress bar smoothly, which will require feedback from whatever method he uses to copy the file. CopyFileEx will provide that feedback, or he could write his own copy function pretty easily too. Combine the feedback with a PeekMessage, DispatchMessage call and he'll be there. No need for threads.
    Yes...that is what I basically assume as well...and that is why I would like to see the actual code and where it is placed at the moment...
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

  5. #20
    Join Date
    Aug 2003
    Posts
    84
    Here ya go.


    [CODE]

    void CCopyDlg::CopyProgress(void)
    {

    //
    m_progress.SetPos(m_progress.GetPos() + 30);

    int copy = CopyFile(m_strFILELOCATION,"A:\\" + m_strFILENAME,FALSE); \\Copying file
    if(copy > 0){
    m_progress.SetPos(m_progress.GetPos() + 60);
    CStdioFile csf;
    csf.Open("a:\\autoexec.bat", CFile::modeWrite | CFile::modeCreate | CFile::typeText);

    \\Need to handle on error for file creation\write.

    m_progress.SetPos(m_progress.GetPos() + 90);
    csf.WriteString(m_strFILENAME);
    csf.Close();
    m_progress.SetPos(m_progress.GetPos() + 100);
    MessageBox("Disk is ready for use", "Done", MB_OK | MB_ICONINFORMATION);
    OnCancel();
    }
    else {
    m_progress.SetPos(m_progress.GetPos() + 100);
    MessageBox("Unable to copy the file " + m_strFILENAME, "ERROR", MB_OK | MB_ICONERROR);
    OnCancel();

    }

    }CODE]
    ____________
    VC++ .NET MFC

  6. #21
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Thank you....okay this is a regular function of your second (modal) dialog. As long as you are within this function the message queue of that dialog will not be processed. In other words, your progress bar will not be updated...

    Since you are updating your progress bar based on some other tasks that you are doing and not only on the copying of the file alone, using 'CopyFileEx()' will not help here much. So, I would suggest that you update the progress bar itself after setting the new position...thus
    Code:
    void CCopyDlg::CopyProgress(void)
    {
      m_progress.SetPos(m_progress.GetPos() + 30);
      m_progress.UpdateWindow();
    
      int copy = CopyFile(m_strFILELOCATION,"A:\\" + m_strFILENAME,FALSE); \\Copying file
      if(copy > 0)
      {
        m_progress.SetPos(m_progress.GetPos() + 60); 
        m_progress.UpdateWindow();
    
        CStdioFile csf;
        csf.Open("a:\\autoexec.bat", CFile::modeWrite | CFile::modeCreate | CFile::typeText);
    
        // Need to handle on error for file creation\write.
    
        m_progress.SetPos(m_progress.GetPos() + 90);
        m_progress.UpdateWindow();
    
        csf.WriteString(m_strFILENAME);
        csf.Close();
    
        m_progress.SetPos(m_progress.GetPos() + 100);
        m_progress.UpdateWindow();
    
        MessageBox("Disk is ready for use", "Done", MB_OK | MB_ICONINFORMATION);
      }
      else
      {
        m_progress.SetPos(m_progress.GetPos() + 100);
        m_progress.UpdateWindow();
    
        MessageBox("Unable to copy the file " + m_strFILENAME, "ERROR", MB_OK | MB_ICONERROR);
      }
    }
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

  7. #22
    Join Date
    Jan 2005
    Posts
    3

    Arrow Re: Progress bar

    Hello guys....I'm a niewbie in coding and i'd like some help....
    Is there a demo of copying some files from a location to another displaying also the copying progress in a progress bar?

    I m using VC++ Studio 6

    Please help me by posting a zip or a link to a FULL tutorial....


    Regards

  8. #23
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: Progress bar

    People that answer questions usually prefer that we look for answers first. Did you look in the articles in the CodeGuru web site and other such web sites? Also, it is usually better to create your own thread rather than adding to someone else's. Using someone else's is often called "hijacking".
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  9. #24
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Progress bar

    Quote Originally Posted by BorBoMoTSaLo
    Hello guys....I'm a niewbie in coding and i'd like some help....
    Is there a demo of copying some files from a location to another displaying also the copying progress in a progress bar?
    SHFileOperation()
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

  10. #25
    Join Date
    Jan 2005
    Posts
    3

    Smile Yes but....

    ok this nethod is called highjacking but i 'd like to learn how can i make my dialog act like this.....

    So is there a link for a simple demo project that copies a file (not counting) from a location to another to help me finish my work?

    I m not an expert and i m not going to be....I just want to add progress bar in
    my personal program.....


    Thanks a lot again

    Regards

  11. #26
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: Yes but....

    Quote Originally Posted by BorBoMoTSaLo
    ok this nethod is called highjacking but i 'd like to learn how can i make my dialog act like this.....
    But if you are inconsiderate to the people you want to help you will get little or no help.
    Quote Originally Posted by BorBoMoTSaLo
    I m not an expert and i m not going to be....I just want to add progress bar in
    my personal program.....
    You don't need to be an expert programmer to be considerate.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  12. #27
    Join Date
    Jan 2005
    Posts
    3

    Question inconsiderate?

    @Sam Hobbs

    Sorry for the annoyance but i trying to find a solution for 2 days.....
    At this time i have nowhere to look searh or something.....I'm just asking for a way to create a realtime progress bar....
    In the beginning is only copy & paste.....Then knowledge rises and you can share it with people that need it....

    I think its very easy for you to create a demo project that does the above work,but for me isn't....
    Everybody was a niewbie at the beginning and i think you know how it feels...

    I'd be thankfull if you could attach a zip file including the workspase of the above program....

    thanks again and i m sorry for the annoyance....

    Regards

  13. #28
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: Progress bar

    You are inconsiderate because you refuse to start a new thread.

    You are inconsiderate if you have not looked in the CodeGuru web site and other such sites for relevant articles.

    You are inconsiderate if you ignored Andreas's answer.

    Even if you did start your own thread, it is unlikely you will get much help if you ask others to do all your work for you. If you don't know how to use SHFileOperation() or anything in an article, then look at it (SHFileOperation or the article) and do the best you can to figure out how to use it. Then ask specific questions. Do that in another thread, not here.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center