Option Explicit
Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As LongPtr, ByVal hdc As LongPtr) As LongPtr
Private Declare PtrSafe Function OpenThemeData Lib "UxTheme.dll" (ByVal hwnd As LongPtr, ByVal LPCWSTR As LongPtr) As LongPtr
Private Declare PtrSafe Function CloseThemeData Lib "UxTheme.dll" (ByVal hTheme As LongPtr) As Long
Private Declare PtrSafe Function DrawThemeBackground Lib "UxTheme.dll" (ByVal hTheme As LongPtr, ByVal hdc As LongPtr, ByVal iPartId As Long, ByVal iStateId As Long, pRect As RECT, ByVal pClipRect As LongPtr) As Long
Private Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Enum PPState
PBFS_NORMAL = 1: PBFS_ERROR: PBFS_PAUSED: PBFS_PARTIAL
End Enum
Private nMax As Double
Private nMin As Double
Private Pz As Long
Private Sub SetProgressRange(ByVal Min As Double, ByVal Max As Double)
nMin = Min
nMax = Max
Pz = -1
End Sub
Private Sub Progress(ByVal Value As Double, Optional State As PPState = PBFS_NORMAL)
Const PP_BAR = 1
Const PP_FILL = 5
Dim hTheme As LongPtr, dc As LongPtr, Dest As RECT
Dim u As Long, dlt As Double
If nMin >= nMax Then Exit Sub
dlt = (Value - nMin) / (nMax - nMin)
u = dlt * 100
If u = Pz Then Exit Sub
Caption = u
Pz = u
On Error GoTo Fin
dc = GetDC(Frame1.[_GethWnd])
GetClientRect Frame1.[_GethWnd], Dest
hTheme = OpenThemeData(0, StrPtr("Progress"))
If Pz = 0 Then
DrawThemeBackground hTheme, dc, PP_BAR, 1, Dest, 0
End If
Dest.Right = Dest.Right * Pz / 100
DrawThemeBackground hTheme, dc, PP_FILL, State, Dest, 0
Fin: CloseThemeData hTheme
ReleaseDC Frame1.[_GethWnd], dc
End Sub
Private Sub CommandButton1_Click()
Dim t As Single, i
t = Timer
SetProgressRange 1, 500
For i = 1 To 500
Progress i, PBFS_PARTIAL
While (Timer - t) < 0.01
DoEvents
Wend
t = Timer
Next
MsgBox "Terminé"
End Sub