?
Solved

Using a progress dislog

Posted on 1998-06-02
3
Medium Priority
?
278 Views
Last Modified: 2013-12-03
I'm using VC++ 4.0 and it has a progress component which I would like to use.
How can I make calls to it? How do I update it?
Source code for displaying and updating it is appreciated
0
Comment
Question by:stefi
[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
3 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 200 total points
ID: 1406119
One nice way is to put the progress control in the status bar.

I have code for this, if you would like.

Another way is to put up a dialog with a progress bar in it.

I also have some smaple code for this .. actually it is a multithreaded version so that the progress bar in the progress dialog can be more easily updated while processing is happening

Some of this is too long to post here .. give me your email address please.

0
 
LVL 11

Expert Comment

by:alexo
ID: 1406120
Suppose you have a short loop of, say, 200 iterations.
You can init the progress bar as (min=0, max=200), set its initial position to (position=0) and its step to (step=1).
Inside the loop, just "step" the progress bar on each iteration.

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1406121
Of course, if you just want a control in a dialog, you may find it easier to use class wizard to create a control member variable for you.  Then you don't need to make SendMessage calls etc as you just use the CProgressCtrl class members.

I am assuming here that you are actually useing MFC (since you said you were talking about VC etc).

If not, the on-line help has sample SDK code calls eg..

Progress Bar Example

The following example shows how to use a progress bar to indicate the progress of a lengthy file-parsing operation. The example creates a progress bar and positions it along the bottom of the parent window's client area. The height of the progress bar is based on the height of the arrow bitmap used in a scroll bar. The range is based on the size of the file divided by 2048, which is the size of each "chunk" of data read from the file. The example also sets an increment and advances the current position of the progress bar by the increment after parsing each chunk.

  // ParseALargeFile - parses a large file and uses a progress bar to
  //   indicate the progress of the parsing operation.
  // Returns TRUE if successful, or FALSE otherwise.
  // hwndParent - parent window of the progress bar.
  // lpszFileName - name of the file to parse.
  //
  // Global variable
  //     g_hinst - instance handle
  extern HINSTANCE g_hinst;
 
  BOOL ParseALargeFile(HWND hwndParent, LPSTR lpszFileName)
  {
    RECT rcClient;  // client area of parent window
    int cyVScroll;  // height of scroll bar arrow
    HWND hwndPB;    // handle of progress bar
    HANDLE hFile;   // handle of file
    DWORD cb;       // size of file and count of bytes read
    LPCH pch;       // address of data read from file
    LPCH pchTmp;    // temporary pointer

    // Ensure that the common control DLL is loaded and create a
    // progress bar along the bottom of the client area of the
    // parent window. Base the height of the progress bar on
    // the height of a scroll bar arrow.
    InitCommonControls();
    GetClientRect(hwndParent, &rcClient);
    cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
    hwndPB = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL,
        WS_CHILD | WS_VISIBLE, rcClient.left,
        rcClient.bottom - cyVScroll,
        rcClient.right, cyVScroll,
        hwndParent, (HMENU) 0, g_hinst, NULL);
 
    // Open the file for reading, and retrieve the size of the file.
    hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ,
        (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);
 
    if (hFile == (HANDLE) INVALID_HANDLE_VALUE)
      return FALSE;
 
    cb = GetFileSize(hFile, (LPDWORD) NULL);
 
    // Set the range and increment of the progress bar.
    SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, cb / 2048));
    SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 1, 0);
 
    // Parse the file.
    pch = (LPCH) LocalAlloc(LPTR, sizeof(char) * 2048);
    pchTmp = pch;
    do {
        ReadFile(hFile, pchTmp, sizeof(char) * 2048, &cb,
            (LPOVERLAPPED) NULL);
        .
        . // Include here any code that parses the file.
        .
 
        // Advance the current position of the progress bar
        // by the increment.
        SendMessage(hwndPB, PBM_STEPIT, 0, 0);
    } while (cb);
    CloseHandle((HANDLE) hFile);
 
    DestroyWindow(hwndPB);
    return TRUE;
  }

0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

764 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