Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26750 Discussions

Using a progress bar in a Windows application


I wanted to try using a progress bar in a Windows application. In my MainWndProc function, in response to the WM_CREATE message, I have the following lines:

        stylePB = ior(ior(WS_CHILD, WS_VISIBLE), PBS_SMOOTH)         !Progress bar, visible
        ID_Progress = 7                                                                                 !ID for progress bar
        hProg = CreateWindowEx(0, "Progress_Class"C, ""C, stylePB, 70, 300, 120, 30, hWnd, ID_Progress, ghInstance, NULL)
        j = SendMessage(hProg, PBM_SETSTEP, 1, 0)
        j = SendMessage(hProg, PBM_STEPIT, 0, 0)

I also have the statement use comctl32 at the start of the function.

The program builds without error, but the main window does not display the progress bar. It does display several other child controls that I also created in the WM_CREATE section of the code.

Can someone let me know what I am doing wrong?


Steve J

0 Kudos
2 Replies
Honored Contributor I

I attached a routine I use to init a progress bars.

    module subroutine cc_progress_bar_init(hwndPB,hwndParent,range_min_in,range_max_in,range_step) !create and init the progress bar
        use ifwin, only : handle, T_RECT, bool, LRESULT, LONG_PTR, UINT_PTR, GetClientRect,&
                          GetSystemMetrics, CreateWindowEx, SendMessage, null,&
        implicit none
        integer(handle),intent(in)   :: hwndParent  ! handle of parent window   
        integer(4), intent(in)       :: range_min_in, range_max_in, range_step
        integer(handle),intent(out)  :: hwndPB      ! Handle of progress bar.
        type(T_RECT)      :: rcClient !  ! Client area of parent window.
        integer(4)        :: cyVScroll;  ! Height of scroll bar arrow.
        integer(bool)     :: bret
        integer(LRESULT)  :: ires
        integer(LONG_PTR) :: lParam_range !or whatever 16 bits max as range is lower part of 32 bit value
        integer(UINT_PTR) :: step 
        integer(LONG_PTR) :: range_min, range_max
        step = range_step        !use variables of the correct integer(kind)
        range_max = range_max_in
        range_min = range_min_in
        lParam_range=ishft(range_max,16) + range_min !hi word, low word 16bit + 16bit
        bret = GetClientRect(hwndParent, rcClient)
        cyVScroll = GetSystemMetrics(SM_CYVSCROLL) 
        !create a progress bar along the bottom of the client area of the parent window. 
        hwndPB = CreateWindowEx(0, PROGRESS_CLASS, NULL, &
                                ior(WS_CHILD, WS_VISIBLE), rcClient%left,& 
                                rcClient%bottom - cyVScroll, &
                                rcClient%right, cyVScroll, &          !and for the record NULL is kind=8 for x64 in ifwinty
                                hwndParent, 0_handle, 0_handle, NULL) !the 0 do not work on x64 04/12/2013 
        ! Set the range and increment of the progress bar. 
        ires = SendMessage(hwndPB, PBM_SETRANGE, 0_fwparam, lParam_range)   
        ires = SendMessage(hwndPB, PBM_SETSTEP, int(step,fwparam), 0_flparam)  
    end subroutine cc_progress_bar_init



Thanks! By using your code, I was able to determine that the problem was using "PROGRESS_CLASS"C as the class for a progress bar in the call to CreateWindowEx. When I switched this to PROGRESS_CLASS, as in your subroutine, it worked.