Progress Bar assistance

I am new to using Visual C++. I used a Control box in the Resource view tab to create the progress bar in the dialog box. This puts all the information in one file. In another file, I want to update the same progress bar so that it looks like it is downloading. How do I do that I've tried everything I could think of which is not much since I am new to this and they don't work.


For example:
one file
Progress.cpp:
Member variable,m_pBar, is what I created for Progress Bar using the class wizard. It was automatically put in this file.

Update.Cpp
I want to update the progress bar in Progress.cpp so that it looks like I am downloading while I am sending information. How do I do that



Answer this question

Progress Bar assistance

  • kaisatsu

    The problem is that I am trying to change the progress bar from another file but it's not working correctly. Nothing is being displayed. I can do it within the same file but when I try to update it from another file, nothing happens.
  • Chadwick Posey

    NewGuy100 wrote:
    The problem is that I am trying to change the progress bar from another file but it's not working correctly. Nothing is being displayed. I can do it within the same file but when I try to update it from another file, nothing happens.

    Show some code snippets please - so that the problem can be identified.



  • PromemoreX

    you can find about in www.codeproject.com

     m_prog.SetRange(int), m_prog.GetPos(int),....



  • edallica

    NewGuy100 wrote:
    Do I have to create another thread If so, how would I do that

    If you want your UI to be responsive during a complex time consuming operation, that should be put into a separate thread. Look up AfxBeginThread on MSDN.



  • EPISWarren

    NewGuy100 wrote:
    Can you tell me which one I should look at I been going through different files but they don't really help me.

    See http://msdn2.microsoft.com/en-us/library/wkb2hwtk.aspx

    It explains how to manipulate the progress bar using MFC. If you click on an individual function, you'll get to that function's reference where there's usually a sample code snippet that shows you exactly what's to be done.



  • mox_01

    Do I have to create another thread If so, how would I do that
  • texwalker

    Okay, your issue is that you need to access the progress bar member from your view class in your document class. It's not good design to modify an UI element from the document class. But in this specific case, you can get a handle to your view using GetFirstViewPosition and GetNextView.

    You could also call UpdateAllViews and have the progress bar suitably updated in the view's OnUpdate override.

    NewGuy100 wrote:

    In one file

    StatisticView.cpp

    void CStatisticView::DoDataExchange(CDataExchange* pDX) {

    CHostLoaderDoc* pDoc = (CHostLoaderDoc*)m_pDocument;
    m_ProgressBar.Format(_T("%.2f"),pDoc->loadTime);

    CFormView::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_PROGRESSBAR1, m_ProgressBar); //created by visual C++

    }

    In the other file

    UpdateBar.cpp

    void CHostLoaderDoc::OnDeviceProgram() {

    //Send some information across serial port. I want to update the progress bar here

    //so that it lets me know that information is being transferred.

    }



  • JesterSoftware

    Can you tell me which one I should look at I been going through different files but they don't really help me.
  • Jeevann

    Thanks, I will try the first one that you mentioned using:

    GetFirstViewPosition and GetNextView in my OnDeviceProgram() function. If that doesn't work, I will look into threads.


  • Ahmed Mohd. Hazzaa

    In one file

    StatisticView.cpp

    void CStatisticView::DoDataExchange(CDataExchange* pDX) {

         CHostLoaderDoc* pDoc = (CHostLoaderDoc*)m_pDocument;
         m_ProgressBar.Format(_T("%.2f"),pDoc->loadTime);

         CFormView::DoDataExchange(pDX);
         DDX_Text(pDX, IDC_PROGRESSBAR1, m_ProgressBar); //created by visual C++

    }

    In the other file

    UpdateBar.cpp

    void CHostLoaderDoc::OnDeviceProgram() {

    //Send some information across serial port. I want to update the progress bar here

    //so that it lets me know that information is being transferred.

    }


  • Shona Arora

    The progress bar is moving much faster than the data is being sent. I want them to go at the same time. Here is what I have.

    CStatisticView.cpp

    void CStatisticView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
    {

    // TODO: Add your specialized code here and/or call the base class
    CHostLoaderDoc* pDoc = (CHostLoaderDoc*)m_pDocument;
    // m_cProgBar.SetRange(0,(unsigned short) pDoc->loadTime);
    m_cProgBar.SetPos(pDoc->loadTemp);

    }

    CHostloaderDoc.cpp

    void CHostLoaderDoc::OnDeviceProgram() {
    VARIANT vOut;
    packet *curr = head;
    unsigned char* ucArray;
    CString ch;

    SendCommand("L\r"); // First send the command (ASCII)
    loadTemp =0;
    CMSComm* pCommCtrl = &(((CMainFrame*)AfxGetMainWnd())->GetStatisticView()->m_Comm);
    vOut.vt = VT_ARRAY|VT_UI1; // Set to array of binary mode for sending
    vOut.parray = SafeArrayCreateVector(VT_UI1,0,70);// Create an array of 128 data + 6 misc bytes
    ucArray=(unsigned char*)vOut.parray->pvData; // Cast the pointer to an array pointer
    ucArray[0]=HEADER; // Head of package
    ucArray[4]=0; // Meanwhile the package type will be data

    while (curr->next) { // Move thru whole prepared package link list
    do {
    // Wait for receiving

    } while (ch!=ACKNOWLEDGE); // Wait for acknowledge character
    if(loadTemp <(unsigned short)loadTime)
    {
    loadTemp++;
    loadTemp = loadTemp/2;
    }
    else
    loadTemp = (unsigned short)loadTime;
    UpdateAllViews(NULL);
    }
    }


  • Progress Bar assistance