Progress Bar (with visual styles)
Progress Bar (with visual styles)
Progress Bar (with visual styles)
Progress Bar (with visual styles)
Progress Bar (with visual styles)
Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles)
Progress Bar (with visual styles) Progress Bar (with visual styles)
Progress Bar (with visual styles)
Go Back  Xtreme Visual Basic Talk > > > Progress Bar (with visual styles)


Reply
 
Thread Tools Display Modes
  #1  
Old 11-05-2016, 11:57 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,829
Default Progress Bar (with visual styles)


I am trying to add an animated progress bar to my app.

In the code below

Method 1 (Command 1) draws the green progress properly but no animation
Method 2 (Command 2) draws the green progress properly but no animation
Method 3 (Command 3) draws the green animation only half way but animates properly

Can anyone help here?

If you try the below code, you can only click one button each time you run the executable

Code:
Option Explicit

' Progress bar window handle
Private hWndPB As Long


Private Sub Form_Initialize()
    Call InitCommonControls
End Sub

Private Sub Form_Load()

    Command1.Caption = "Method 1"
    Command2.Caption = "Method 2"
    Command3.Caption = "Method 3"
    
    ' Create the progress bar
    hWndPB = CreateWindowEX(0, PROGRESS_CLASS, "", WS_VISIBLE Or WS_CHILD, _
                            50, 20, 200, 25, _
                            Me.hwnd, _
                            0&, App.hInstance, 0&)
    ' Set the bar's parent
    Call SetParent(hWndPB, Me.hwnd)
    
End Sub

Private Sub Form_Unload(Cancel As Integer)
    
    ' Destroy the progress bar
    DestroyWindow hWndPB
    
End Sub

Private Sub Command1_Click()
    
    Dim i As Long
    
    For i = 1 To 100
        Call SendMessageLong(hWndPB, PBM_SETPOS, i, 0)
    Next i
    
End Sub


Private Sub Command2_Click()

    Dim i As Long
    
    ' Set the range of the progess bar.
    ' PBM_SETRANGE message expresses the range as 16-bit unsigned integer,
    ' therefore min & max values must be from 0 to 65,535
    
    ' &H4E20 = 20,000
    Call SendMessage(hWndPB, PBM_SETRANGE, 0, ByVal (&H4E20 * &H10000))
    
  
    ' Set progress bar increment
    Call SendMessage(hWndPB, PBM_SETSTEP, 1, 0)

    ' Demo
    'For i = 1 To &H4FFF
    For i = 1 To &H4E20
        Call SendMessage(hWndPB, PBM_STEPIT, 0, 0)
    Next i
    
End Sub


Private Sub Command3_Click()

    Dim i As Long
    
    Call SendMessage(hWndPB, PBM_SETRANGE32, 0, 1000000)
    
    Call SendMessage(hWndPB, PBM_SETSTEP, 50, 0)

    For i = 1 To 1000000
        Call SendMessage(hWndPB, PBM_STEPIT, 0, 0)
    Next i
    
End Sub

Last edited by mms; 11-06-2016 at 12:07 AM.
Reply With Quote
  #2  
Old 11-06-2016, 09:53 PM
fafalone fafalone is offline
Freshman
 
Join Date: May 2010
Posts: 34
Default

The animation stops when the maximum is reached. That's the way it's supposed to work. If you never want it to stop, there's the marquee style (but that won't reflect percentage done). In #3 I believe it's an issue because you're going from 1 to 50,000,000 when the max is 1,000,000
Reply With Quote
  #3  
Old 11-07-2016, 06:34 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,829
Default

Thanks,

By animation, I mean the light colored "reflection" travelling inside the green progress indication.

This "animation" doesn't happen when I execute the code, as it does in #3, or in other Microsoft controls that use this type of progress indicator.
Reply With Quote
  #4  
Old 11-07-2016, 05:15 PM
Cerian Knight's Avatar
Cerian KnightProgress Bar (with visual styles) Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,143
Default

It might be a good idea to see all the related API Declares, Constants and UDTs that you are using.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #5  
Old 11-08-2016, 11:41 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,829
Default

Below is complete code for test project.

I got code in Command1 and Command2 to work.

Command1 shows "reflection" in progress bar constantly moving until progress reaches 100%

In Command2, I set the range of the progress bar to 200, and have it set that the upper limit is never reached, and the "reflection" constantly moves until the form is closed.

I still can't get Command3 to work. It is the same code as for Command2, except it uses PBM_SETRANGE32 instead of PBM_SETRANGE.

As before, you can only test one command button with each instance of the app.

Form
Code:
Option Explicit

' Progress bar window handle
Private hWndPB As Long


Private Sub Form_Initialize()
    Call InitCommonControls
End Sub

Private Sub Form_Load()
    
    ' Create the progress bar
    hWndPB = CreateWindowEX(0, PROGRESS_CLASS, "", WS_VISIBLE Or WS_CHILD, _
                            40, 10, 160, 25, _
                            Me.hwnd, _
                            0&, App.hInstance, 0&)
    ' Set the bar's parent
    Call SetParent(hWndPB, Me.hwnd)
    
End Sub

Private Sub Form_Unload(Cancel As Integer)
    
    ' Destroy the progress bar
    DestroyWindow hWndPB
    
End Sub

Private Sub Command1_Click()
    
    Dim i As Long

    For i = 1 To 500000
        DoEvents                                    'so that Label1 will update at each iteration
        Label1.Caption = i / 500000 * 100 & "%"     'make a lengthy operation
        If i Mod (500000 / 100) = 0 Then
            Call SendMessage(hWndPB, PBM_SETPOS, i / 500000 * 100, 0)
        End If
    Next i
    
End Sub


Private Sub Command2_Click()

    Dim i As Long
    
    ' Set the range of the progess bar.
    ' PBM_SETRANGE message expresses the range as 16-bit unsigned integer,
    ' therefore min & max values must be from 0 to 65,535
    
    ' 0 (lParam low word) to &HFFFF (lParam high word).
    ' &HC8 = 200
    Call SendMessage(hWndPB, PBM_SETRANGE, 0, ByVal (&HC8 * &H10000))

    ' Set progress bar increment
    Call SendMessage(hWndPB, PBM_SETSTEP, 1, 0)

    ' Demo
    For i = 1 To 500000
        DoEvents                                    'so that Label1 will update at each iteration
        Label1.Caption = i / 500000 * 100 & "%"     'make a lengthy operation
        If i Mod (500000 / 100) = 0 Then
            Call SendMessage(hWndPB, PBM_SETPOS, i / 500000 * 100, 0)
        End If
    Next i
    
End Sub


Private Sub Command3_Click()

    Dim i As Long
    
    Call SendMessage(hWndPB, PBM_SETRANGE32, 0, 100)
    
    Call SendMessage(hWndPB, PBM_SETSTEP, 1, 0)

    For i = 1 To 500000
        DoEvents                                    'so that Label1 will update at each iteration
        Label1.Caption = i / 500000 * 100 & "%"     'make a lengthy operation
        If i Mod (500000 / 100) = 0 Then
            Call SendMessage(hWndPB, PBM_SETPOS, i / 500000 * 100, 0)
        End If
    Next i
    
End Sub
Module1
Code:
Option Explicit

Public Declare Function CreateWindowEX Lib "user32" Alias "CreateWindowExA" _
    (ByVal dwExStyle As Long, _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String, _
    ByVal dwStyle As Long, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal nWidth As Long, _
    ByVal nHeight As Long, _
    ByVal hWndParent As Long, _
    ByVal hMenu As Long, _
    ByVal hInstance As Long, lpParam As Any) _
    As Long
     
Public Declare Function DestroyWindow Lib "user32" _
    (ByVal hwnd As Long) As Long
 
Public Declare Function SetParent Lib "user32" _
    (ByVal hWndChild As Long, _
    ByVal hWndNewParent As Long) As Long
     
Public Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam _
    As Long, lParam As Any) As Long

Public Const GWL_STYLE As Long = -16

Public Const WM_USER = &H400
Public Const WS_VISIBLE = &H10000000
Public Const WS_CHILD = &H40000000

Public Const CCM_FIRST = &H2000
Public Const CCM_SETBKCOLOR = (CCM_FIRST + 1)

Public Const PROGRESS_CLASS = "msctls_progress32"

Public Const PBS_SMOOTH = &H1
Public Const PBS_VERTICAL = &H4
Public Const PBS_MARQUEE As Long = &H8&

Public Const PBST_NORMAL As Long = &H1&
Public Const PBST_ERROR As Long = &H2&
Public Const PBST_PAUSED As Long = &H3&

Public Const PBM_SETRANGE = (WM_USER + 1)
Public Const PBM_SETPOS = (WM_USER + 2)
Public Const PBM_DELTAPOS = (WM_USER + 3)
Public Const PBM_SETSTEP = (WM_USER + 4)
Public Const PBM_STEPIT = (WM_USER + 5)
Public Const PBM_SETRANGE32 = (WM_USER + 6)
Public Const PBM_GETRANGE = (WM_USER + 7)
Public Const PBM_GETPOS = (WM_USER + 8)
Public Const PBM_SETBARCOLOR = (WM_USER + 9)
Public Const PBM_SETBKCOLOR = CCM_SETBKCOLOR
Public Const PBM_SETMARQUEE = (WM_USER + 10)
Public Const PBM_SETSTATE As Long = (WM_USER + 16)
Module2
Code:
Option Explicit

Private Type tagInitCommonControlsEx
    lngSize As Long
    lngICC As Long
End Type

Private Const ICC_USEREX_CLASSES = &H200

Private Declare Function InitCommonControlsEx Lib "comctl32" _
    (iccex As tagInitCommonControlsEx) As Boolean


Public Sub InitCommonControls()
    
    Dim iccex As tagInitCommonControlsEx
     
    iccex.lngSize = LenB(iccex)
    iccex.lngICC = ICC_USEREX_CLASSES

    On Error Resume Next
    InitCommonControlsEx iccex
    
End Sub
Reply With Quote
Reply

Tags
call, private, sendmessagehwndpb, bar, progress, set, method, dim, hwndpb, &h4e20, me.hwnd, pbm_setrange, range, pbm_setstep, integer, pbm_stepit, expresses, command2_click, message, progess, pbm_setpos, &h10000, byval, 20, 000, increment


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Progress Bar (with visual styles)
Progress Bar (with visual styles)
Progress Bar (with visual styles) Progress Bar (with visual styles)
Progress Bar (with visual styles)
Progress Bar (with visual styles)
Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles) Progress Bar (with visual styles)
Progress Bar (with visual styles)
Progress Bar (with visual styles)
 
Progress Bar (with visual styles)
Progress Bar (with visual styles)
 
-->