Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1470

TaskbarButton Progress

$
0
0
Lightweight, no typelib used just DispCallFunc() hacking.

Requires Windows 7 or later, but the manifest is optional. Works in the IDE but uses subclassing so be cautious.

Demo client Form included:

Code:

Option Explicit

Private Const PROG_TOTAL As Long = 500

Private ProgCompleted As Long
Private WithEvents TaskbarList3 As TaskbarList3

Private Sub Command1_Click()
    TaskbarList3.SetProgressState TBPF_NORMAL
    Command1.Enabled = False
    Timer1.Enabled = True
End Sub

Private Sub Form_Initialize()
    'Could also do this in a Form_Load event handler instead:
    Set TaskbarList3 = New TaskbarList3
    TaskbarList3.ConnectFormToShell32 Me
End Sub

Private Sub Form_Unload(Cancel As Integer)
    'Redundant since we are unloading anyway.  But normally you'd do this once
    'the action's indicated progress has completed, so we'll show it here:
    With TaskbarList3
        If .Connected Then .SetProgressState TBPF_NOPROGRESS
    End With
End Sub

Private Sub TaskbarList3_Connected()
    Command1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    With TaskbarList3
        If .Connected Then 'Redundant test here, because to get here the Connected
                          'event has been raised so that Command1 got enabled so that
                          'the user could have pressed it so that Timer1 got enabled.
            ProgCompleted = ProgCompleted + 1
            If ProgCompleted > PROG_TOTAL Then ProgCompleted = 0
            .SetProgressValue ProgCompleted, PROG_TOTAL
        End If
    End With
End Sub

Run the demo. Click on Start and watch the Taskbar button. Even works minimized.

You can pause it or mark it "error" and so on as well.
Attached Files

Viewing all articles
Browse latest Browse all 1470

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>