We help IT Professionals succeed at work.

how to control a progressbar?

krydea
krydea asked
on
hello,
i got a questoin about  a progressbar i don't konw how to control them and exely i what to have some function's one create <- that creats a window or a dialog with one set that can change the progress value and one close.
can you help me one may way plz.

al you know is welcome plz help.

carlos smith
Comment
Watch Question

Commented:
Just like all other Windows controls, you manipulate a progress bar by sending it messages.  Here is some sample code from MSDN but I'd suggest you look it up yourself since there is a lot of good explanation there also:

     // 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;
     }
 

Author

Commented:
thanx i understant most psrt of it:).
but can you make thouse 3 function for the 80 point's? (plz plz plz)

Author

Commented:
plz

Commented:
What is it that you don't understand?

Author

Commented:
furst i made:
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by dialog.rc
//
#define IDD_DIALOG1                     101
#define IDC_PROGRESS1                   1001
#define IDC_STATIC                      -1

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        102
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1002
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

and this:
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// Dutch (Netherlands) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NLD)
#ifdef _WIN32
LANGUAGE LANG_DUTCH, SUBLANG_DUTCH
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_DIALOG1 DIALOG DISCARDABLE  0, 0, 186, 95
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,129,7,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,129,24,50,14
    CONTROL         "Progress1",IDC_PROGRESS1,"msctls_progress32",WS_BORDER,
                    7,59,163,14
    LTEXT           "Static",IDC_STATIC,13,13,60,8
    LTEXT           "Static",IDC_STATIC,13,28,70,11
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
    IDD_DIALOG1, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 179
        TOPMARGIN, 7
        BOTTOMMARGIN, 88
    END
END
#endif    // APSTUDIO_INVOKED


#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED

#endif    // Dutch (Netherlands) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

with mnvc on school and i whant to control it normal with C or C++ and i whas doing stoepit case i thougt when i know how to control a progressbar i would know how the set static text etc.. it's for i filetranfer app. the static are for the sended byt's and the total byt's.... i got 25 poin't more. plz help.

Author

Commented:
plz help..
you get this question to it's the same plz plz.. need help. and plz don't ask money case i'm 15 and don't got teh money...
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=cprog&qid=20187547

Commented:
What is it that you don't understand.  The example I posted above it complete.

Author

Commented:
i didn't ask my question clear i what to cointrol something in a dialog if you don't what to asnwer that about the static and the progressbar plz do it about the progressbar allone.
or can you add to that source up how to mut 2 static's in the window 1 wiht file size and the adder one hwo fare it is!?... plz help..
Commented:
I posted souce code that demonstrates the use of a progress control and how to send windows messages to it.

Again (and for the LAST TIME) what part of this don't you understand?

Author

Commented:
plz men help. i need something else.. what is this biznis i'm asking for some thing is it all about the point's?..:(

btw: i think i understand it.

Author

Commented:
??????????????????

Explore More ContentExplore courses, solutions, and other research materials related to this topic.