Thread: Has anyone worked with...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001

    Question Has anyone worked with...

    Has anyone ever worked with progress bars? I am wanting to use them, but I am practicing progressing the bar while reading a file. I use CreateFile then read it. Here's some code:


    HWND hwndPB;

    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

    SendMessage(hwndPB, PBM_SETBARCOLOR, 0, RGB(16,26,150));

    // 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.
    hwndPB = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL,
    400, 20,
    hwnd, (HMENU) 0, 0, NULL);

    // Open the file for reading, and retrieve the size of the file.
    hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ,

    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,

    // Advance the current position of the progress bar
    // by the increment.
    SendMessage(hwndPB, PBM_STEPIT, cb, 0);
    } while (cb);

    When I do that, though, it shows a progress bar, but no progress from STEPIT. I have tried:

    SendMessage(hwndPB, PBM_STEPIT, 0, cb);

    but it doesn't work either. What do I do? I got most of the code from MSDN!


    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer
    Try adding a paint msg.


    I use
       SendMessage( GetDlgItem(hwndPB,IDC_PROGRESS), PBM_STEPIT, (WPARAM) 0, 0);
    My hwndPB is of the dialog containing the progress bar though, you would use your hwndPB.

    Read the help as to what the (HMENU) parameter of the CreateWindowEx() should be. I think this will also be causing a problem.
    Thats right you use bloodshed
    This is from MSVC

    "For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window."

    The progress is a child of the dialog. Can you be 100% it does not have another ctrl with ID = 0?
    Use a hash define and check for confilcts in your resource.h
    Last edited by novacain; 12-13-2001 at 01:47 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Have you worked too hard?!
    By Sentral in forum A Brief History of
    Replies: 4
    Last Post: 07-22-2006, 04:33 AM
  2. using dll's, worked before not now?
    By Rune Hunter in forum C++ Programming
    Replies: 1
    Last Post: 10-10-2005, 02:31 PM
  3. Any of you Worked with Shared Memory in Linux?
    By zahid in forum Linux Programming
    Replies: 7
    Last Post: 02-02-2003, 10:53 AM
  4. Worked, then made it a function: Console
    By RoD in forum C++ Programming
    Replies: 3
    Last Post: 01-04-2003, 03:46 PM
  5. counting program worked, but test file CRASHES IT.. WHY?
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 05-19-2002, 02:29 AM