Date: 02-16-2022
Return to Index
created by gbSnippets
'Credit: Pierre Bellisle
'Compilable Example: (Jose Includes)
'Playing with the new powerfull taskbar under Windows Se7en
'Use the taskbar button application as a progress bar
'Have fun, Pierre
'http://msdn.microsoft.com/en-us/magazine/dd942846.aspx
'http://fsoriano.developpez.com/articles/windows7/delphi/utilisez-barre-taches-windows-7-dans-vos-applications-delphi-2010/
#Compile Exe '#Win 8.04#
#Dim All
#Register None
#Include "Win32Api.inc"
Global hDlg As Dword
%Label1 = 101
%Button1 = 201
%TimerOne = 301
%TBPF_NOPROGRESS = 0
%TBPF_INDETERMINATE = 1
%TBPF_NORMAL = 2
%TBPF_ERROR = 4
%TBPF_PAUSED = 8
%CLSCTX_INPROC_SERVER = 1
$CLSID_TaskbarList = Guid$("{56FDF344-FD6D-11D0-958A-006097C9A090}")
$IID_ITaskbarList3 = Guid$("{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}")
'______________________________________________________________________________
Function M_CALLs(ByVal ObjectPtr As Dword, ByVal MethodName As Dword, Optional ByVal v1 As Dword, _
ByVal v2 As Dword, ByVal v3 As Dword, ByVal v4 As Dword, ByVal v5 As Dword) As Long
'Thank you José...
! push v5 'Push parameter 5
! push v4 'Push parameter 4
! push v3 'Push parameter 3
! push v2 'Push parameter 2
! push v1 'Push parameter 1
! mov eax, ObjectPtr 'Move pointer to COM object into eax
! mov ecx, MethodName 'Move method to execute into ecx
! push eax
! mov eax, [eax] 'Move pointer to eax into eax
! CALL DWORD PTR [eax + ecx] 'Call method offset
! mov FUNCTION, eax 'Move return value into function
End Function
'______________________________________________________________________________
CallBack Function DlgProc() As Long
Static CLSID_TaskbarList As String * 16
Static IID_ITaskbarList3 As String * 16
Static pTaskBar As Dword Pointer
Static WM_TASKBARBUTTONCREATED As Dword
Static TaskbarButtonCreated As Dword
Static ProgressPos As Dword
Static ProgressMax As Dword
Static ProgressState As Long
Static TimerStarted As Long
Static Delta As Long
Local RetVal As Long
Select Case CbMsg
Case %WM_InitDialog
IID_ITaskbarList3 = $IID_ITaskbarList3
CLSID_TaskbarList = $CLSID_TaskbarList
ProgressPos = 0
ProgressMax = 100
ProgressState = %TBPF_NORMAL
Delta = 1
'Windows need time to create the taskbar button before we can play with it.
'So wait until we receive designated WM_TASKBARBUTTONCREATED message
WM_TASKBARBUTTONCREATED = RegisterWindowMessage("TaskbarButtonCreated")
Case WM_TASKBARBUTTONCREATED 'Message sent by Windows 7 after the creation of the taskbar button
TaskbarButtonCreated = %TRUE
CoInitialize(ByVal %NULL)
If CoCreateInstance(ByVal VarPtr(CLSID_TaskbarList), ByVal 0, %CLSCTX_INPROC_SERVER, _
ByVal VarPtr(IID_ITaskbarList3), pTaskBar) = %S_Ok Then
Retval = M_CALLs(pTaskBar, 12, hDlg) '%HrInit
'Retval = M_CALLs(pTaskBar, 40, hDlg, BYVAL %TBPF_NORMAL) 'SetProgressState Green
'Retval = M_CALLs(pTaskBar, 40, hDlg, BYVAL %TBPF_ERROR) 'SetProgressState Red
'Retval = M_CALLs(pTaskBar, 40, hDlg, BYVAL %TBPF_PAUSED) 'SetProgressState Yellow
Retval = M_CALLs(pTaskBar, 40, hDlg, ByVal %TBPF_INDETERMINATE) 'Green marquee
'Retval = M_CALLs(pTaskBar, 40, hDlg, BYVAL %TBPF_NOPROGRESS) 'No progress
'Retval = M_CALLs(pTaskBar, 36, hDlg, BYVAL ProgressPos, 0, BYVAL ProgressMax, 0) 'SetProgressValue
End If
Case %WM_Command
Select Case LoWrd(CbWParam)
Case %Button1
If CbCtlMsg = %BN_Clicked Then
If TaskbarButtonCreated Then
If TimerStarted = %FALSE Then
TimerStarted = %TRUE
SetTimer(hDlg, %TimerOne, 10, ByVal %NULL)
Control Set Text hDlg, %Button1, "&Stop"
Control Set Text hDlg, %Label1, "TBPF_NORMAL"
Else
TimerStarted = %FALSE
KillTimer(hDlg, %TimerOne)
Control Set Text hDlg, %Button1, "&Start"
Control Set Text hDlg, %Label1, "TBPF_INDETERMINATE"
Retval = M_CALLs(pTaskBar, 40, hDlg, ByVal %TBPF_INDETERMINATE) 'Green marquee
End If
Else
MessageBox hDlg, "Need at least Windows Se7ven !", "TaskBArProgress", %MB_IconInformation Or %MB_Ok
End If
End If
End Select
Case %WM_Timer
If CbWParam = %TimerOne Then
ProgressPos = ProgressPos + Delta
M_CALLs(pTaskBar, 36, hDlg, ByVal ProgressPos, 0, ByVal ProgressMax, 0) 'SetProgressValue
If ProgressPos = ProgressMax Then
Delta = - 1
End If
If ProgressPos = 0 Then
Delta = 1
If ProgressState = %TBPF_NORMAL Then
ProgressState = %TBPF_ERROR
Control Set Text hDlg, %Label1, "TBPF_ERROR"
ElseIf ProgressState = %TBPF_ERROR Then
ProgressState = %TBPF_PAUSED
Control Set Text hDlg, %Label1, "TBPF_PAUSED"
Else
ProgressState = %TBPF_NORMAL
Control Set Text hDlg, %Label1, "TBPF_NORMAL"
End If
M_CALLs(pTaskBar, 40, hDlg, ProgressState) 'SetProgressState
End If
End If
Case %WM_Destroy
If TaskbarButtonCreated Then
If TimerStarted Then
KillTimer(hDlg, %TimerOne)
End If
CoUninitialize
End If
End Select
End Function
'______________________________________________________________________________
Function PBMain()
Dialog New %HWND_Desktop, "Taskbar Progress ", , , 200, 100, %WS_Caption Or %WS_MinimizeBox Or _
%WS_MaximizeBox Or %WS_SysMenu Or %WS_ThickFrame, 0 To hDlg
SetClassLong(hDlg, %GCL_HICON, LoadIcon(ByVal %NULL, ByVal %IDI_INFORMATION)) 'Icon from Windows
Control Add Button, hDlg, %Button1, "Start", 85, 35, 35, 15
Control Add Label, hDlg, %Label1, "ProgressBar in Taskbar button : TBPF_INDETERMINATE", _
5, 60, 190, 15, %SS_Center
Dialog Show Modal hDlg Call DlgProc
End Function
'_________________
'gbs_01289
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm