Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinApi.au3>
#include <GdiPlus.au3>
Global $ahCallBack[2], $iPrecent
$Gui = GUICreate("Gradient ProgressBar", 400, 300)
GUICtrlCreateLabel("", 9, 9, 302, 22, -1, $WS_EX_STATICEDGE)
GUICtrlCreateLabel("", 9, 39, 302, 22, -1, $WS_EX_STATICEDGE)
GUICtrlCreateLabel("There is few more colors commented in the script bellow...", 10, 200)
$Status_Label = GUICtrlCreateLabel("0%", 330, 30, 30, 20)
$Button = GUICtrlCreateButton("Start",150,100,50,20)
_GDIPlus_Startup()
$hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($Gui)
$hBitMap = _GDIPlus_BitmapCreateFromGraphics(300, 20, $hGraphic1)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitMap)
$hPen = _GDIPlus_PenCreate(0,1)
$Depth = 1.64 ; Min = 1.10 Max = 1.70
For $i = 1 To 20
;~ $PenColor = "0xFF" & Hex(255 - $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "3B" ; Orange
;~ $PenColor = "0xFF" & Hex(255 - $i, 2) & Hex(Round(200 - $i^$Depth), 2) & "FF" ; Magenta
;~ $PenColor = "0xFF" & Hex(80 + $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "3B" ; Green
$PenColor = "0xFF" & Hex(80 + $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "FF" ; Blue
_GDIPlus_PenSetColor($hPen, $PenColor)
_GDIPlus_GraphicsDrawLine($hGraphic2, 0, $i-1, 300, $i-1, $hPen)
Next
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic2)
$hBitMap_Multiply = _GDIPlus_BitmapCreateFromGraphics(300, 20, $hGraphic1)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitMap_Multiply)
For $i = 0 To 15 Step 5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic2, $hBitMap, 0, 0, 300, 20, 0, $i, 300, 5)
Next
_GDIPlus_GraphicsDispose($hGraphic2)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button
If $iPrecent = 0 Then _WinAPI_RedrawWindow($Gui)
If GUICtrlRead($Button) = "Stop" Then
GUICtrlSetData($Button, "Start")
CallBack_Free($ahCallBack)
ContinueLoop
EndIf
GUICtrlSetData($Button, "Stop")
$ahCallBack = CallBack_Init("Paint_Proc", 10)
Case $GUI_EVENT_CLOSE
If $ahCallBack Then CallBack_Free($ahCallBack)
_GDIPlus_ImageDispose($hBitmap)
_GDIPlus_ImageDispose($hBitMap_Multiply)
_GDIPlus_GraphicsDispose($hGraphic1)
_GDIPlus_Shutdown()
Exit
EndSwitch
WEnd
Func Paint_Proc($hWnd, $nMsg, $wParam, $lParam)
$iPrecent += 1
GUICtrlSetData($Status_Label, Round($iPrecent / 3) & "%")
If $iPrecent > 300 Then
$iPrecent = 0
GUICtrlSetData($Status_Label, "100%")
GUICtrlSetData($Button, "Start")
CallBack_Free($ahCallBack)
$ahCallBack = 0
Dim $ahCallBack[2] = [-1, -1]
EndIf
_GDIPlus_GraphicsDrawImageRectRect($hGraphic1, $hBitMap, 0, 0, $iPrecent, 20, 10, 10, $iPrecent, 20)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic1, $hBitMap_Multiply, 0, 0, $iPrecent, 20, 10, 40, $iPrecent, 20)
EndFunc
Func CallBack_Init($sFuncName, $iTime, $sParam = "hwnd;int;int;dword")
Local $hCallBack = DLLCallbackRegister($sFuncName, "int", $sParam)
Local $aTimer = DllCall("user32.dll", "uint", "SetTimer", _
"hwnd", 0, "uint", 0, "int", $iTime, "ptr", DllCallbackGetPtr($hCallBack))
Local $ahCallBack[2] = [$hCallBack, $aTimer[0]]
Return $ahCallBack
EndFunc
Func CallBack_Free($ahCallBack)
If $ahCallBack[0] <> -1 Then DllCallbackFree($ahCallBack[0])
If $ahCallBack[1] <> -1 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $ahCallBack[1])
EndFunc