CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2001
    Location
    San Diego
    Posts
    102

    CProgressCtrl problem

    How do I get the stdout to fill in the step in a progress bar. Here is what I have so far.
    Code:
      CProgressCtrl *m_pFileProg = (CProgressCtrl *)GetDlgItem(IDC_FILEPROG);
    
      STARTUPINFO SUInfo;
      PROCESS_INFORMATION PInfo;
      SUInfo.cb = sizeof SUInfo;
      SUInfo.lpReserved = NULL;
      SUInfo.lpDesktop = NULL;
      SUInfo.lpTitle = NULL;
      SUInfo.dwX = 0;
      SUInfo.dwY = 0;
      SUInfo.dwFlags = NULL; //If I uncomment this, the output is a command prompt showing nothing /*STARTF_USESTDHANDLES;*/
      SUInfo.cbReserved2 = 0;
      SUInfo.lpReserved2 = 0;
      SUInfo.hStdOutput = PInfo.hProcess;
    
     //sBatchEncode is a CString containing the executable command and it's arguments 		
      CreateProcess(NULL, (LPTSTR)((LPCTSTR)sBatchEncode),NULL,NULL, FALSE//TRUE if I uncomment the above, NORMAL_PRIORITY_CLASS, NULL, NULL,&SUInfo, &PInfo);
    
    //Currently the output on the command prompt is 0%....25%....50%....75%....100%.... 	
      SetDlgItemText(IDC_STATIC_CONVERTFILE,"Processing " + sInFile);
    
      WaitForSingleObject( PInfo.hProcess, INFINITE );
    
      CloseHandle(PInfo.hProcess);
      CloseHandle(PInfo.hThread);
    }
    How do I current the CProgressCtrl to show the process steps?

    Am I using CreateProcess correctly or should I use something else to accomplishing what I want to do?

    Been trying to figure this out and need help.
    Mike@spb

  2. #2
    Join Date
    Aug 2001
    Location
    North Bend, WA
    Posts
    1,947
    How do I current the CProgressCtrl to show the process steps?
    [code]

    // initialize progress control
    m_pFileProg ->SetRange(myminimum, mymaximum);

    ...
    Where you report progress...
    m_pFileProg->SetPos(SomewhereBetweenMinAndMax);

    Am I using CreateProcess correctly or should I use something else to accomplishing what I want to do?
    Does it do what you want now? What are you trying to do?

  3. #3
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: CProgressCtrl problem

    I have issue with the function call:

    Code:
    DOF_m_fault_progress.SetPos(100);
    There is a slight delay before the progress bar updates to 100%.
    Any idea why this issue occurs.

    Before setting the progress bar to 100 I am setting it to 10-20-40-50-75 % and they seem to be working fine.

    I have set the range to 1 to 100 as shown in the below function call:

    Code:
    DOF_m_fault_progress.SetRange(0,100);

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CProgressCtrl problem

    And what happens in your code between SetPos(75) and SetPos(100)?
    Victor Nijegorodov

  5. #5
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: CProgressCtrl problem

    I am calling 2 applications using"ShellExecute" command which decode some files and generate some new files.
    Once the control is returned from those I am using these SetPos() command to update the progress accordingly.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CProgressCtrl problem

    Quote Originally Posted by vcdebugger View Post
    I am calling 2 applications using"ShellExecute" command which decode some files and generate some new files.
    Once the control is returned from those I am using these SetPos() command to update the progress accordingly.
    So what is the problem?
    Victor Nijegorodov

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: CProgressCtrl problem

    The progress bar is an indicator of tasks performed, not time elapsed. If the tasks to perform don't take the same amount of time, then the indicated progress won't be linear. This non-linear progress indication is common in programs (eg MS update etc). If 10% of the tasks to be performed have completed in 10 seconds, then you cannot say that 100% will complete in 100 seconds. They might complete in 50 seconds or they might complete in 10 minutes.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CProgressCtrl problem

    You could try adding DOF_m_fault_progress.UpdateWindow() to force it to update immediately.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured