
Code: Select all
;======================================================================
; Module: TaskBarProgress.pbi
;
; Author: Thomas (ts-soft) Schulz
; Date: Sep 04, 2015
; Version: 1.4
; Target Compiler: PureBasic 5.2+
; Target OS: Windows 7 +
; License: Free, unrestricted, no warranty whatsoever
; Use at your own risk
;======================================================================
; History:
; Version 1.4
; API-Update for PB5.40
; Version 1.3
; added optional setting for range of progress
; (min = 0 To max) (max = min To 9223372036854775807)
DeclareModule TaskBarProgress
#TBPF_NOPROGRESS = $0
#TBPF_INDETERMINATE = $1
#TBPF_NORMAL = $2
#TBPF_ERROR = $4
#TBPF_PAUSED = $8
Interface TaskBarProgress
GetState.i()
GetValue.i()
SetState(state.i)
SetValue(value.i)
Destroy()
EndInterface
Declare TBP_New(hWnd.i, min.q = 0, max.q = 100)
EndDeclareModule
Module TaskBarProgress
EnableExplicit
Interface ITaskbarList3 Extends ITaskbarList2
SetProgressValue.i(hWnd.i, ullCompleted.q, ullTotal.q)
SetProgressState.i(hWnd.i, tbpFlags.l)
RegisterTab.i(hWndTab.i, hWndMDI.i)
UnregisterTab.i(hWndTab.i)
SetTabOrder.i(hWndTab.i, hWndInsertBefore.i)
SetTabActive.i(hWndTab.i, hWndMDI.i, tbatFlags.l)
ThumbBarAddButtons.i(hWnd.i, cButtons.l, *pButton)
ThumbBarUpdateButtons.i(hWnd.i, cButtons.l, *pButton)
ThumbBarSetImageList.i(hWnd.i, himl.i)
SetOverlayIcon.i(hWnd.i, hIcon.i, pszDescription.s)
SetThumbnailTooltip.i(hWnd.i, pszTip.s)
SetThumbnailClip.i(hWnd.i, *prcClip)
EndInterface
Structure TBPClass
*vTable
hWnd.i
ptl.ITaskbarList3
state.i
value.i
min.q
max.q
EndStructure
Procedure TBP_New(hWnd.i, min.q = 0, max.q = 100)
Protected *obj.TBPClass
Protected ptl.ITaskbarList3
If OSVersion() < #PB_OS_Windows_7
Debug "You're OS is to old ;-)"
ProcedureReturn #False
EndIf
If min < 0 : min = 0 : EndIf
If max < min : max = min : EndIf
*obj = AllocateMemory(SizeOf(TBPClass))
If *obj
*obj\vTable = ?vTable_TBPClass
*obj\hWnd = hWnd
CoCreateInstance_(?CLSID_TaskBarList, 0, 1, ?IID_ITaskBarList3, @ptl)
If ptl
ptl\HrInit()
ptl\SetProgressValue(hWnd, min, max)
ptl\SetProgressState(hWnd, #TBPF_NOPROGRESS)
*obj\ptl = ptl
*obj\state = #TBPF_NOPROGRESS
*obj\value = 0
*obj\min = min
*obj\max = max
EndIf
EndIf
ProcedureReturn *obj
EndProcedure
; Methodes
Procedure GetState(*this.TBPClass)
If *this
ProcedureReturn *this\state
EndIf
EndProcedure
Procedure GetValue(*this.TBPClass)
If *this
ProcedureReturn *this\value
EndIf
EndProcedure
Procedure SetState(*this.TBPClass, state)
If *this
With *this
If \ptl
Select state
Case #TBPF_NOPROGRESS, #TBPF_INDETERMINATE, #TBPF_NORMAL, #TBPF_ERROR, #TBPF_PAUSED
\ptl\SetProgressState(\hWnd, state)
\state = state
EndSelect
EndIf
EndWith
EndIf
EndProcedure
Procedure SetValue(*this.TBPClass, value)
If *this
With *this
If \ptl
If value < \min : value = \min : EndIf
If value > \max : value = \max : EndIf
\ptl\SetProgressValue(\hWnd, value, \max)
\value = value
EndIf
EndWith
EndIf
EndProcedure
Procedure Destroy(*this.TBPClass)
If *this
If *this\ptl
*this\ptl\Release()
EndIf
FreeMemory(*this)
EndIf
EndProcedure
DataSection
CLSID_TaskBarList:
Data.l $56FDF344
Data.w $FD6D, $11D0
Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
IID_ITaskBarList3:
Data.l $ea1afb91
Data.w $9e28,$4b86
Data.b $90,$E9,$9e,$9f,$8a,$5e,$ef,$af
vTable_TBPClass:
Data.i @GetState()
Data.i @GetValue()
Data.i @SetState()
Data.i @SetValue()
Data.i @Destroy()
EndDataSection
EndModule
; example
CompilerIf #PB_Compiler_IsMainFile
EnableExplicit
UseModule TaskBarProgress
Define TBP.TaskBarProgress
Define progress
Define hIcon = ExtractIcon_(GetModuleHandle_(#Null$), #PB_Compiler_Home + "PureBasic.exe", 0)
OpenWindow(0, #PB_Ignore, #PB_Ignore, 265, 30, "Example", #PB_Window_SystemMenu)
SendMessage_(WindowID(0), #WM_SETICON, 0, hIcon)
ButtonGadget(0, 5, 5, 80, 20, "start")
ButtonGadget(1, 90, 5, 80, 20, "stop")
ButtonGadget(2, 175, 5, 80, 20, "pause")
TBP = TBP_New(WindowID(0))
If Not TBP
MessageRequester("TaskBarProgress", "You're OS is to old ;-)")
End
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
TBP\Destroy()
DestroyIcon_(hIcon)
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 0 ; start
AddWindowTimer(0, 1, 100)
Case 1 ; stop
RemoveWindowTimer(0, 1)
TBP\SetState(#TBPF_NOPROGRESS)
progress = 0
Case 2 ; pause
Select TBP\GetState()
Case #TBPF_INDETERMINATE
AddWindowTimer(0, 1, 100)
TBP\SetState(#TBPF_NORMAL)
SetGadgetText(2, "pause")
Default
RemoveWindowTimer(0, 1)
TBP\SetState(#TBPF_INDETERMINATE)
SetGadgetText(2, "continue")
EndSelect
EndSelect
Case #PB_Event_Timer
progress + 1
If progress > 100 : progress = 0 : EndIf
TBP\SetState(#TBPF_NORMAL)
TBP\SetValue(progress)
EndSelect
ForEver
CompilerEndIf