#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.16.1 Author: Prog@ndy - after Script from nobbe ( 2008 in http://www.autoitscript.com/forum/index.php?s=&showtopic=64703&view=findpost&p=485031 ) Author: UEZ - https://www.autoitscript.com/forum/topic/150545-gdi-animated-loading-screens-build-2014-06-20-32-examples/ Author: Benners made from code mashed together from links #ce ---------------------------------------------------------------------------- #AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;~ #Tidy_Parameters=/sf #include-once #include #include #include #include #include #include #include #include #Region globals #Region Global constant values Global Enum _ ; types of progress bar 0/1 $eMPB_vTypeStd, _ $eMPB_vTypeMarquee Global Enum _ ; pcent visibility $eMPB_cShowPcent $eMPB_vPcentOff = False, _ $eMPB_vPcentOn = True Global Enum _ ; make progress striped $eMPB_cStripe $eMPB_vStripeOff = False, _ $eMPB_vStripeOn = True Global Enum _ ; stripe drawing direction $eMPB_cStripeDir $eMPB_vStripeDirBck, _ $eMPB_vStripeDirFwd Global Const _ ; $eMPB_cTextStyle $GUI_FONTBOLD = 1 Global Enum _ ; progress bar text alignment $eMPB_cTextAlign $eMPB_vTextLeft, _ $eMPB_vTextCenter, _ $eMPB_vTextRight Global Enum _ ; $eMPB_cTextFormat $eMPB_vTextPCent, _ $eMPB_vTextAll #EndRegion Global constant values Global Enum _ ; progress bar 0 row $eMPB_PBCnt, _ ;_ just a zero but used to locate pbar count and others below $eMPB_CBHandle, _ ;_ callback function handle $eMPB_CBTimer, _ ;_ callback time handle $eMPB_CBCount ;_ number of times callback has been initialised Global Enum _ ; progress bar properties $eMPB_cID, _ ;_ controls ID ### start of create function parameters $eMPB_cWidth, _ ;_ controls width $eMPB_cHeight, _ ;_ controls height $eMPB_cFgColour, _ ;_ controls foreground colour $eMPB_cBgColour, _ ;_ controls background colour $eMPB_cBorder, _ ;_ controls style: border, no border $eMPB_cType, _ ;_ controls type: normal, marquee $eMPB_cShowPcent, _ ;_ display the text on the control $eMPB_cStripe, _ ;_ controls pattern: plain, striped $eMPB_cStripeDir, _ ;_ direction the stripes are drawn ### end of create function parameters $eMPB_cText, _ ;_ text to be displayed ### start of text properties $eMPB_cTextFont, _ ;_ font for the text $eMPB_cTextColour, _ ;_ Font colour for the text $eMPB_cTextStyle, _ ;_ Font style for the text $eMPB_cTextAlign, _ ;_ text alignment. Left Right, Center $eMPB_cTextFormat, _ ;_ text layout: text, text and percentage $eMPB_cPcentVal, _ ;_ controls value $eMPB_cFontLayout, _ ;_ position on the progress bar where the text will be displayed $eMPB_cPenSize, _ ;_ size of pen2 ### DONT CHANGE BELOW THIS LINE #### $eMPB_cFont, _ ;_ set the font for the progress text ### start of GDI+ resource clean up (in deletion order) $eMPB_FontFamily, _ ;_ font family for the progress test $eMPB_FontFormat, _ ;_ format for the progress text $eMPB_FontBrush, _ ;_ brush object for the progress text $eMPB_cPen1, _ ;_ pen for drawing the progress foreground $eMPB_cPen2, _ ;_ pen for the bottom highlight $eMPB_cBackBmpCtxt, _ ;_main bitmap context $eMPB_cPbarBmpCtxt, _ ;_progress strip context $eMPB_cPbarbmp, _ ;_ progress strip bitmap $eMPB_cLineBrush, _ ;_ brush for the top highlight gradient $eMPB_cBackbmp, _ ;_ main bitmap for the overall progress image ### end of GDI+ resource clean up $eMPB_cMax #Region values array Global $__g_avPBars[1][$eMPB_cMax] = [[ _ 0, _ ;_ $eMPB_PBCnt -1, _ ;_ $eMPBCBHandle -1, _ ;_ $eMPBCBTimer 0, _ ;_ $eMPBCBCount 'iBgColour', _ 'iBorder', _ 'iType', _ 'bShowPcent', _ 'bStripe', _ 'iStripeDir', _ 'sText', _ 'sTextFont', _ 'iTextColour', _ 'iTextStyle', _ 'iTextAlign', _ 'iTextFormat', _ 'iPcentVal', _ 'FontLayout', _ 'PenSize', _ 'hFont', _ 'hFontFamily', _ 'hFontFormat', _ 'hFontBrush', _ 'hPen1', _ 'hPen2', _ 'hBackBmpCtxt', _ 'hPbarBmpCtxt', _ 'hPbarbmp', _ 'hLineBrush', _ 'hBackbmp']] ;_ progress bar and callback settings array #EndRegion values array #EndRegion globals Global $hGui = GUICreate("Test", 400, 150) Global $idPcent_sld = GUICtrlCreateSlider(5, 20, 310, 30) Global $idPcent_lbl = GUICtrlCreateLabel("0%", 330, 30, 30, 20) Global $idChange_btn = GUICtrlCreateButton("Stop", 220, 90, 75, 25, 0) Global $id_SetText_btn = GUICtrlCreateButton("Start", 100, 90, 75, 25, 0) Global $sText_inp = GUICtrlCreateInput("", 20, 90, 75, 25) ;~ Global $iID = _MPB_CreateProgress(10, 60, 300, 17) ; $vFgColour $vBgColour $iBorder $bType bShowPcent $bStripe $iStripeDir) Global $iID = _MPB_CreateProgress(10, 60, 300, 25, '0xFFAC9090', '0xFFE2CFCF', Default, $eMPB_vTypeMarquee, $eMPB_vPcentOn, $eMPB_vStripeOff, $eMPB_vStripeDirfwd) ;~ Global $iID = _MPB_CreateProgress(10, 60, 300, 25, '0xFFAC9090', '0xFFE2CFCF', Default, default, $eMPB_vPcentOn, $eMPB_vStripeOn, $eMPB_vStripeDirfwd) If @error Then MsgBox(0, @error, $iID) Global $iPercent = 0 GUISetState() While 1 Switch GUIGetMsg() Case $idChange_btn $__g_avPBars[$iID][$eMPB_cPcentVal] = 0 Case $id_SetText_btn _GDIp_SetMarqueeSpeed($iID) ;~ For $i = 1 To 100 ;~ GUICtrlSetData($idPcent_lbl, _MPB_SetProgressValue($iID, $i) & '%') ;~ sleep(50) ;~ next Case $GUI_EVENT_CLOSE _MPB_Shutdown() Exit EndSwitch ;~ $iPercent +=1 ;~ ;~ If $iPercent <> GUICtrlRead($idPcent_sld) Then ;~ $iPercent = GUICtrlRead($idPcent_sld) ;~ GUICtrlSetData($idPcent_lbl, _MPB_SetProgressValue($iID, $iPercent) & '%') ;~ EndIf WEnd Func _GDIp_SetMarqueeSpeed(ByRef $iID, $iSpeed = 2) If Not __MPB_ValidateProgressArray($iID) Then Return SetError(1, 0, 0) If $iSpeed < 0 Then $__g_avPBars[$iID][$eMPB_cPcentVal] = _WinAPI_LoWord($__g_avPBars[$iID][$eMPB_cPcentVal]) Return 1 EndIf If $iSpeed > 10 Then $iSpeed = 10 If $iSpeed < 1 Then $iSpeed = 1 $__g_avPBars[$iID][$eMPB_cPcentVal] = _WinAPI_MakeLong(_WinAPI_LoWord($__g_avPBars[$iID][$eMPB_cPcentVal]), Number($iSpeed)) Return 1 EndFunc ;==>_GDIp_SetMarqueeSpeed Func __MPB_CheckForGDIPlus($bFatal = True) Local $hDll = DllOpen("GDIPlus.dll") Local $avDll = DllCall("Kernel32.dll", "dword", "GetModuleHandle", "str", "GDIPlus") DllClose($hDll) If $avDll[0] = 0 And $bFatal Then _WinAPI_FatalAppExit("GDIplus not found. Please install GDIplus to use this application") Return ($avDll[0] = 0) EndFunc ;==>__MPB_CheckForGDIPlus Func __MPB_ConvertToARGB($vColor) Local $iDefault = '0xFF00FF66' If IsString($vColor) Then ; Trim "0x" prefix using regex if present $vColor = StringRegExpReplace($vColor, "^(?:0x|#)?(.*)$", "$1") ; Validate the string is a valid hexadecimal color If Not StringRegExp($vColor, "^(?:[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$") Then ; Invalid format $vColor = $iDefault Else ; Check if it's in RGB format (6 digits) or ARGB format (8 digits) If StringLen($vColor) == 6 Then $vColor = "FF" & $vColor ; Convert to ARGB format (add "FF" for alpha) $vColor = "0x" & $vColor EndIf ElseIf IsInt($vColor) Then ; Convert integer to hexadecimal string $vColor = Hex($vColor, 8) If StringLeft($vColor, 2) = '00' Then ; it's actually a 6-digit RGB value padded to 8 digits $vColor = StringMid($vColor, 3, 6) $vColor = 'FF' & $vColor EndIf $vColor = "0x" & $vColor ; Return in ARGB format Else ; Invalid input type $vColor = $iDefault EndIf Return $vColor EndFunc ;==>__MPB_ConvertToARGB Func __MPB_CreateBackBmp($iID) ; $hBitmap $__g_avPBars[$iID][$eMPB_cBackbmp] = _GDIPlus_BitmapCreateFromScan0( _ $__g_avPBars[$iID][$eMPB_cWidth], _ ;_ bitmap width in pixels. $__g_avPBars[$iID][$eMPB_cHeight]) ;_ bitmap height in pixels. If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_BitmapCreateFromScan0 (Backbmp)')) $__g_avPBars[$iID][$eMPB_cBackBmpCtxt] = _GDIPlus_ImageGetGraphicsContext($__g_avPBars[$iID][$eMPB_cBackbmp]) If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_ImageGetGraphicsContext (BackBmpCtxt)')) _GDIPlus_GraphicsSetPixelOffsetMode($__g_avPBars[$iID][$eMPB_cBackBmpCtxt], $GDIP_PIXELOFFSETMODE_HIGHQUALITY) If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_GraphicsSetPixelOffsetMode (BackBmpCtxt)')) EndFunc ;==>__MPB_CreateBackBmp Func __MPB_CreateLineBrush($iID) ; $hLineBrush ; Creates a LinearGradientBrush object $__g_avPBars[$iID][$eMPB_cLineBrush] = _GDIPlus_LineBrushCreate( _ $__g_avPBars[$iID][$eMPB_cWidth] / 2, _ ;_ $nX1 - X coordinate of the starting point of the gradient 0, _ ;_ $nY1 - Y coordinate of the starting point of the gradient $__g_avPBars[$iID][$eMPB_cWidth] / 2, _ ;_ $nX2 - X coordinate of the ending point of the gradient. $__g_avPBars[$iID][$eMPB_cHeight] / 3, _ ;_ $nY2 - Y coordinate of the ending point of the gradient. 0xB0FFFFFF, _ ;_ $iARGBClr1 - Alpha, Red, Green and Blue components of the starting color of the line 0x00FFFFFF) ;_ $iARGBClr2 - Alpha, Red, Green and Blue components of the ending color of the line If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_LineBrushCreate')) EndFunc ;==>__MPB_CreateLineBrush Func __MPB_CreatePbarBmp(ByRef $iID) ; $hBmp $__g_avPBars[$iID][$eMPB_cPbarbmp] = _GDIPlus_BitmapCreateFromScan0( _ $__g_avPBars[$iID][$eMPB_cHeight] * 2, _ ;_ $iWidth $__g_avPBars[$iID][$eMPB_cHeight]) ;_ $iLen If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_BitmapCreateFromScan0 (PbarBmp)')) $__g_avPBars[$iID][$eMPB_cPbarBmpCtxt] = _GDIPlus_ImageGetGraphicsContext($__g_avPBars[$iID][$eMPB_cPbarbmp]) ; $hCtxt_Bmp If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_ImageGetGraphicsContext')) EndFunc ;==>__MPB_CreatePbarBmp Func __MPB_CreatePens(ByRef $iID) ; $hPen, $hPen2 ; set the pensize for pen2 $__g_avPBars[$iID][$eMPB_cPenSize] = Int($__g_avPBars[$iID][$eMPB_cHeight] / 15) $__g_avPBars[$iID][$eMPB_cPen1] = _GDIPlus_PenCreate($__g_avPBars[$iID][$eMPB_cFgColour]) If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_PenCreate (Pen1)')) $__g_avPBars[$iID][$eMPB_cPen2] = _GDIPlus_PenCreate( _ 0x50000000, _ ;_ $iARGB - Alpha, Red, Green and Blue components of pen color Int($__g_avPBars[$iID][$eMPB_cHeight] / 15)) ;_ nWidth - The width of the pen If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_PenCreate (Pen2)')) EndFunc ;==>__MPB_CreatePens Func __MPB_DrawString(ByRef $iID) $__g_avPBars[$iID][$eMPB_FontBrush] = _GDIPlus_BrushCreateSolid($__g_avPBars[$iID][$eMPB_cTextColour]) ; brush If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_BrushCreateSolid')) $__g_avPBars[$iID][$eMPB_FontFormat] = _GDIPlus_StringFormatCreate() ; format If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_StringFormatCreate')) $__g_avPBars[$iID][$eMPB_FontFamily] = _GDIPlus_FontFamilyCreate($__g_avPBars[$iID][$eMPB_cTextFont]) ; family If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_FontFamilyCreate')) $__g_avPBars[$iID][$eMPB_cFont] = _GDIPlus_FontCreate($__g_avPBars[$iID][$eMPB_FontFamily], Round($__g_avPBars[$iID][$eMPB_cHeight] * 3 / 5), $__g_avPBars[$iID][$eMPB_cTextStyle]) ; font If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_FontCreate')) $__g_avPBars[$iID][$eMPB_cFontLayout] = _GDIPlus_RectFCreate(0, 2, $__g_avPBars[$iID][$eMPB_cWidth], $__g_avPBars[$iID][$eMPB_cHeight]) ; layout If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_RectFCreate')) _GDIPlus_StringFormatSetAlign($__g_avPBars[$iID][$eMPB_FontFormat], $__g_avPBars[$iID][$eMPB_cTextAlign]) ; If @error Then Return SetError(1, 0, __MPB_GetLastError(@extended, '_GDIPlus_StringFormatSetAlign')) EndFunc ;==>__MPB_DrawString Func __MPB_DrawStripes(ByRef $iID) Local $iLen = $__g_avPBars[$iID][$eMPB_cHeight] ; Local Static $iX = 0 For $iY = 0 To $__g_avPBars[$iID][$eMPB_cHeight] - 1 ; keep Switch $__g_avPBars[$iID][$eMPB_cStripeDir] Case 1 _GDIPlus_GraphicsDrawLine($__g_avPBars[$iID][$eMPB_cPbarBmpCtxt], $iX + $iY, $iY, $iX + $iY + $iLen, $iY, $__g_avPBars[$iID][$eMPB_cPen1]) _GDIPlus_GraphicsDrawLine($__g_avPBars[$iID][$eMPB_cPbarBmpCtxt], $iX + $iY - 2 * $iLen, $iY, $iX + $iY - 1 * $iLen, $iY, $__g_avPBars[$iID][$eMPB_cPen1]) Case Else _GDIPlus_GraphicsDrawLine($__g_avPBars[$iID][$eMPB_cPbarBmpCtxt], -$iX + $iY, $iY, -$iX + $iY + $iLen, $iY, $__g_avPBars[$iID][$eMPB_cPen1]) _GDIPlus_GraphicsDrawLine($__g_avPBars[$iID][$eMPB_cPbarBmpCtxt], -$iX + $iY + 2 * $iLen, $iY, -$iX + $iY + 3 * $iLen, $iY, $__g_avPBars[$iID][$eMPB_cPen1]) EndSwitch Next $iX = Mod($iX + 1, $iLen * 2) ; update x to draw the moving stripes EndFunc ;==>__MPB_DrawStripes Func __MPB_FreeProgressCallback($bForce = False) $__g_avPBars[$eMPB_PBCnt][$eMPB_CBCount] -= 1 ; decrement to keep track of the number of initializations. ; check if we've over done the decrement If $__g_avPBars[$eMPB_PBCnt][$eMPB_CBCount] < 0 Then ; reset to 0 $__g_avPBars = 0 Return EndIf If (Not $bForce) And ($__g_avPBars[$eMPB_PBCnt][$eMPB_CBCount] > 0) Then Return ; return without freeing the timer. ; forces the freeing of the timer even if the reference count is > 0 ; free the callback function ; kill the timer If $__g_avPBars[$eMPB_PBCnt][$eMPB_CBHandle] <> -1 Then DllCallbackFree($__g_avPBars[$eMPB_PBCnt][$eMPB_CBHandle]) If $__g_avPBars[$eMPB_PBCnt][$eMPB_CBTimer] <> -1 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $__g_avPBars[$eMPB_PBCnt][$eMPB_CBTimer]) ; reset the array values $__g_avPBars[$eMPB_PBCnt][$eMPB_CBHandle] = -1 $__g_avPBars[$eMPB_PBCnt][$eMPB_CBTimer] = -1 $__g_avPBars[$eMPB_PBCnt][$eMPB_CBCount] = 0 EndFunc ;==>__MPB_FreeProgressCallback Func __MPB_GetDllError($iError = 0) Local $sErr = '' Switch $iError Case 1 $sErr = 'Unable to use the DLL file' Case 2 $sErr = 'Unknown "return type"' Case 3 $sErr = 'Function not found in the DLL file' Case 4 $sErr = 'Bad number of parameters' Case 5 $sErr = 'Bad parameter' EndSwitch Return $sErr EndFunc ;==>__MPB_GetDllError Func __MPB_GetLastError($iExtended, $sInfo = '') Local $sErrMsg = 'Unknown error (' & $iExtended & ')' Switch $iExtended Case $GDIP_ERROK $sErrMsg = 'Method call was successful' & ' (' & $sInfo & ')' Case $GDIP_ERRGENERICERROR $sErrMsg = 'Generic method call error' & ' (' & $sInfo & ')' Case $GDIP_ERRINVALIDPARAMETER $sErrMsg = 'One of the arguments passed to the method was not valid' & ' (' & $sInfo & ')' Case $GDIP_ERROUTOFMEMORY $sErrMsg = 'The operating system is out of memory' & ' (' & $sInfo & ')' Case $GDIP_ERROBJECTBUSY $sErrMsg = 'One of the arguments in the call is already in use' & ' (' & $sInfo & ')' Case $GDIP_ERRINSUFFICIENTBUFFER $sErrMsg = 'A buffer is not large enough' & ' (' & $sInfo & ')' Case $GDIP_ERRNOTIMPLEMENTED $sErrMsg = 'The method is not implemented' & ' (' & $sInfo & ')' Case $GDIP_ERRWIN32ERROR $sErrMsg = 'The method generated a Microsoft Win32 error' & ' (' & $sInfo & ')' Case $GDIP_ERRWRONGSTATE $sErrMsg = 'The object is in an invalid state to satisfy the API call' & ' (' & $sInfo & ')' Case $GDIP_ERRABORTED $sErrMsg = 'The method was aborted' & ' (' & $sInfo & ')' Case $GDIP_ERRFILENOTFOUND $sErrMsg = 'The specified image file or metafile cannot be found' & ' (' & $sInfo & ')' Case $GDIP_ERRVALUEOVERFLOW $sErrMsg = 'The method produced a numeric overflow' & ' (' & $sInfo & ')' Case $GDIP_ERRACCESSDENIED $sErrMsg = 'A write operation is not allowed on the specified file' & ' (' & $sInfo & ')' Case $GDIP_ERRUNKNOWNIMAGEFORMAT $sErrMsg = 'The specified image file format is not known' & ' (' & $sInfo & ')' Case $GDIP_ERRFONTFAMILYNOTFOUND $sErrMsg = 'The specified font family cannot be found' & ' (' & $sInfo & ')' Case $GDIP_ERRFONTSTYLENOTFOUND $sErrMsg = 'The specified style is not available for the specified font' & ' (' & $sInfo & ')' Case $GDIP_ERRNOTTRUETYPEFONT $sErrMsg = 'The font retrieved is not a TrueType font' & ' (' & $sInfo & ')' Case $GDIP_ERRUNSUPPORTEDGDIVERSION $sErrMsg = 'The installed GDI+ version is incompatible' & ' (' & $sInfo & ')' Case $GDIP_ERRGDIPLUSNOTINITIALIZED $sErrMsg = 'The GDI+ API is not in an initialized state' & ' (' & $sInfo & ')' Case $GDIP_ERRPROPERTYNOTFOUND $sErrMsg = 'The specified property does not exist in the image' & ' (' & $sInfo & ')' Case $GDIP_ERRPROPERTYNOTSUPPORTED $sErrMsg = 'The specified property is not supported' & ' (' & $sInfo & ')' Case 30 $sErrMsg = $sInfo & '(missing)' Case 31 $sErrMsg = 'Failed to create control' & ' (' & $sInfo & ')' Case 32 $sErrMsg = 'Failed to delete control' Case Else EndSwitch Return $sErrMsg EndFunc ;==>__MPB_GetLastError Func __MPB_InitProgressCallback($ForceReInit = False) Local $iTime = 50, $sParam = "hwnd;int;int;dword" $__g_avPBars[$eMPB_PBCnt][$eMPB_CBCount] += 1 ; increment to keep track of the number of initializations If $__g_avPBars[$eMPB_PBCnt][$eMPB_CBCount] > 1 And Not $ForceReInit Then Return True ; skip to avoid multiple initializations If $ForceReInit Then ; re-initialization timer even if it is already initialized. Local $iInit = $__g_avPBars[$eMPB_PBCnt][$eMPB_CBCount] ; temporarily stores the number of initialisations __MPB_FreeProgressCallback(True) ; free the existing timer, $__g_avPBars[$eMPB_PBCnt][$eMPB_CBCount] = $iInit ; restore the number of initialisations EndIf ; register the function to call Local $hCallBack = DllCallbackRegister("__MPB_PaintProgressBars", "int", $sParam) If $hCallBack = 0 Then Return SetError(1, 0, 'Failed to Intialise callback (DllCallbackRegister)') ; start a timer Local $aTimer = DllCall("user32.dll", "uint", "SetTimer", _ "hwnd", 0, "uint", 0, "int", $iTime, "ptr", DllCallbackGetPtr($hCallBack)) If @error Then Local $iErr = @error DllCallbackFree($hCallBack) Return SetError(1, 0, __MPB_GetDllError($iErr)) EndIf $__g_avPBars[$eMPB_PBCnt][$eMPB_CBHandle] = $hCallBack ; stores the callback handle $__g_avPBars[$eMPB_PBCnt][$eMPB_CBTimer] = $aTimer[0] ; stores the timer handle Return True EndFunc ;==>__MPB_InitProgressCallback Func __MPB_PaintProgressBars($hWnd, $nMsg, $wParam, $lParam) #forceref $hWnd, $nMsg, $wParam, $lParam For $i = 1 To UBound($__g_avPBars) - 1 If Not ($__g_avPBars[$i][0] = -1) Then __MPB_RefreshProgress($i) ; Next EndFunc ;==>__MPB_PaintProgressBars Func __MPB_RefreshProgress(ByRef $iID, $iPcent = $__g_avPBars[$iID][$eMPB_cPcentVal]) If Not __MPB_ValidateProgressArray($iID) Then Return SetError(1, 0, 0) If $__g_avPBars[$iID][$eMPB_cWidth] < 1 Then Return SetError(2, 0, 0) ; reset the images for drawing _GDIPlus_GraphicsClear($__g_avPBars[$iID][$eMPB_cBackBmpCtxt], 0xFFF0F0F0) ; $hBitmap _GDIPlus_GraphicsClear($__g_avPBars[$iID][$eMPB_cPbarBmpCtxt], $__g_avPBars[$iID][$eMPB_cBgColour]) ; $hbmp Local $iWidth = $iPcent / 100 * $__g_avPBars[$iID][$eMPB_cWidth] Local $nX = 0 ; the progress is a marquee type so change function If $__g_avPBars[$iID][$eMPB_cPcentVal] > 65535 Then $iPcent = _WinAPI_LoWord($__g_avPBars[$iID][$eMPB_cPcentVal]) If $iPcent > 100 Then $iPcent = 0 If $iPcent < 0 Then $iPcent = 0 $__g_avPBars[$iID][$eMPB_cPcentVal] = _WinAPI_MakeLong($iPcent + _WinAPI_HiWord($__g_avPBars[$iID][$eMPB_cPcentVal]), _WinAPI_HiWord($__g_avPBars[$iID][$eMPB_cPcentVal])) $nX = ($iPcent = 0) ? (0) : ($iPcent / 100 * $__g_avPBars[$iID][$eMPB_cWidth]) $iWidth = 60 Else If $iPcent < 0 Then $iPcent = 0 If $iPcent > 100 Then $iPcent = 100 $__g_avPBars[$iID][$eMPB_cPcentVal] = $iPcent EndIf ; draw stripes on progress if requested If $__g_avPBars[$iID][$eMPB_cStripe] = $eMPB_vStripeOn Then __MPB_DrawStripes($iID) ; draws bottom highlight line _GDIPlus_GraphicsDrawLine( _ $__g_avPBars[$iID][$eMPB_cPbarBmpCtxt], _ 0, _ $__g_avPBars[$iID][$eMPB_cHeight] - $__g_avPBars[$iID][$eMPB_cPenSize] / 2, _ $__g_avPBars[$iID][$eMPB_cHeight] * 2, _ $__g_avPBars[$iID][$eMPB_cHeight] - $__g_avPBars[$iID][$eMPB_cPenSize] / 2, _ $__g_avPBars[$iID][$eMPB_cPen2]) ; draws the gradient on the progress image _GDIPlus_GraphicsFillRect( _ $__g_avPBars[$iID][$eMPB_cPbarBmpCtxt], _ 0, _ 0, _ $__g_avPBars[$iID][$eMPB_cWidth], _ $__g_avPBars[$iID][$eMPB_cHeight] / 3, _ $__g_avPBars[$iID][$eMPB_cLineBrush]) ; apply the texture brush to fill the progress area Local $hTextureBrush = _GDIPlus_TextureCreate($__g_avPBars[$iID][$eMPB_cPbarbmp]) _GDIPlus_GraphicsFillRect( _ $__g_avPBars[$iID][$eMPB_cBackBmpCtxt], _ $nX, _ ; change to $nX - 60 and its's better from the left but resets before it clears the right side (obvs because it's - 60) 0, _ $iWidth, _ $__g_avPBars[$iID][$eMPB_cHeight], _ $hTextureBrush) ; normal _GDIPlus_GraphicsSetTextRenderingHint($__g_avPBars[$iID][$eMPB_cBackBmpCtxt], $GDIP_TEXTRENDERINGHINTANTIALIAS) _GDIPlus_BrushDispose($hTextureBrush) ; determine progress bar text string Local $sPbarText = $__g_avPBars[$iID][$eMPB_cText] If $__g_avPBars[$iID][$eMPB_cShowPcent] = True Then _ $sPbarText &= ($__g_avPBars[$iID][$eMPB_cType] = $eMPB_vTypeMarquee) ? (' ' & StringReplace(" ", " ", ".", Mod(@SEC, 5) + 1)) : (' ' & $iPcent & '%') _GDIPlus_GraphicsDrawStringEx( _ $__g_avPBars[$iID][$eMPB_cBackBmpCtxt], _ ;_ Handle to a Graphics object $sPbarText, _ ;_ String to be drawn $__g_avPBars[$iID][$eMPB_cFont], _ ;_ Handle to the font to use to draw the string $__g_avPBars[$iID][$eMPB_cFontLayout], _ ;_ $tagGDIPRECTF structure that bounds the string $__g_avPBars[$iID][$eMPB_FontFormat], _ ;_ Handle to the string format to draw the string $__g_avPBars[$iID][$eMPB_FontBrush]) ;_ Handle to the brush to draw the string Local $hB = GUICtrlSendMsg($__g_avPBars[$iID][$eMPB_cID], $STM_SETIMAGE, 0, _GDIPlus_BitmapCreateHBITMAPFromBitmap($__g_avPBars[$iID][$eMPB_cBackbmp])) If $hB Then _WinAPI_DeleteObject($hB) EndFunc ;==>__MPB_RefreshProgress Func __MPB_SetArrayValue(ByRef $iID, $iName, $vValue) If $vValue = Default Then Switch $iName Case $eMPB_cWidth $vValue = 200 Case $eMPB_cHeight $vValue = 17 Case $eMPB_cFgColour $vValue = '0xFF00EE00' Case $eMPB_cBgColour $vValue = '0XFF41FF41' Case $eMPB_cBorder $vValue = $WS_BORDER ; -1 Case $eMPB_cType $vValue = $eMPB_vTypeStd Case $eMPB_cShowPcent $vValue = $eMPB_vPcentOff Case $eMPB_cStripe $vValue = $eMPB_vStripeOff Case $eMPB_cStripeDir $vValue = $eMPB_vStripeDirFwd Case $eMPB_cText $vValue = '' Case $eMPB_cTextFont $vValue = 'Arial' Case $eMPB_cTextColour $vValue = 0xFF000000 Case $eMPB_cTextStyle $vValue = $GUI_FONTNORMAL Case $eMPB_cTextAlign $vValue = $eMPB_vTextCenter Case $eMPB_cTextFormat $vValue = $eMPB_vTextPCent EndSwitch EndIf ; update the correct array element $__g_avPBars[$iID][$iName] = $vValue Return $vValue EndFunc ;==>__MPB_SetArrayValue Func __MPB_ValidateProgressArray(ByRef $iID) If Not IsArray($__g_avPBars) Or UBound($__g_avPBars, 2) <> $eMPB_cMax Or UBound($__g_avPBars) < ($iID - 1) Then Return False Return True EndFunc ;==>__MPB_ValidateProgressArray Func _MPB_Shutdown($iID = 0) Local $iStart = ($iID = 0) ? (1) : ($iID) Local $iEnd = ($iID = 0) ? ($__g_avPBars[$eMPB_PBCnt][$eMPB_PBCnt]) : ($iID) Local $sErr = '' ; release the GDI+ objects For $i = $iStart To $iEnd _GDIPlus_FontDispose($__g_avPBars[$i][$eMPB_cFont]) If @error Then ConsoleWrite('_GDIPlus_FontDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_FontFamilyDispose($__g_avPBars[$i][$eMPB_FontFamily]) If @error Then ConsoleWrite('_GDIPlus_FontFamilyDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_StringFormatDispose($__g_avPBars[$i][$eMPB_FontFormat]) If @error Then ConsoleWrite('_GDIPlus_StringFormatDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_BrushDispose($__g_avPBars[$i][$eMPB_FontBrush]) If @error Then ConsoleWrite('_GDIPlus_BrushDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_PenDispose($__g_avPBars[$i][$eMPB_cPen1]) If @error Then ConsoleWrite('_GDIPlus_PenDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_PenDispose($__g_avPBars[$i][$eMPB_cPen2]) If @error Then ConsoleWrite('_GDIPlus_PenDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_GraphicsDispose($__g_avPBars[$i][$eMPB_cBackBmpCtxt]) If @error Then ConsoleWrite('_GDIPlus_GraphicsDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_GraphicsDispose($__g_avPBars[$i][$eMPB_cPbarBmpCtxt]) If @error Then ConsoleWrite('_GDIPlus_GraphicsDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_BitmapDispose($__g_avPBars[$i][$eMPB_cPbarbmp]) If @error Then ConsoleWrite('_GDIPlus_BitmapDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_BrushDispose($__g_avPBars[$i][$eMPB_cLineBrush]) If @error Then ConsoleWrite('_GDIPlus_BrushDispose: ' & __MPB_GetLastError(@extended) & @CRLF) _GDIPlus_BitmapDispose($__g_avPBars[$i][$eMPB_cBackbmp]) If @error Then ConsoleWrite('_GDIPlus_BitmapDispose: ' & __MPB_GetLastError(@extended) & @CRLF) Next If @error Then $sErr = __MPB_GetLastError(@extended) If Not $iID Then ; complete a full shutdown __MPB_FreeProgressCallback(1) ;_ Free the timer _GDIPlus_Shutdown() ;_ Clean up resources used by Microsoft Windows GDI+ Else ; ; reset the array column values for the deleted progress bar For $i = $eMPB_cID To $eMPB_cMax - 1 $__g_avPBars[$iID][$i] = -1 Next EndIf If $sErr <> '' Then Return SetError(1, 0, $sErr) EndFunc ;==>_MPB_Shutdown Func _MPB_CreateProgress($iLeft, $iTop, $iWidth = Default, $iHeight = Default, $vFgColour = Default, $vBgColour = Default, $iBorder = Default, $bType = Default, $bShowPcent = Default, $bStripe = Default, $iStripeDir = Default) __MPB_CheckForGDIPlus() ; Displays a message box and terminates the application ; get an id number from the array Local $iID = $__g_avPBars[$eMPB_PBCnt][$eMPB_PBCnt] + 1 ;_ increase the control count ReDim $__g_avPBars[$iID + 1][$eMPB_cMax] ;_ resize the array $__g_avPBars[$eMPB_PBCnt][$eMPB_PBCnt] = $iID ;_ add the control id to the array ; create the picture control $__g_avPBars[$iID][$eMPB_cID] = GUICtrlCreatePic('', $iLeft, $iTop, _ __MPB_SetArrayValue($iID, $eMPB_cWidth, $iWidth), _ __MPB_SetArrayValue($iID, $eMPB_cHeight, $iHeight), _ __MPB_SetArrayValue($iID, $eMPB_cBorder, $iBorder)) If Not $__g_avPBars[$iID][$eMPB_cID] Then Return SetError(1, 0, __MPB_GetLastError(31, 'GUICtrlCreatePic')) GUICtrlSetBkColor($__g_avPBars[$iID][$eMPB_cID], $GUI_BKCOLOR_TRANSPARENT) If $vFgColour = Default Then $vFgColour = __MPB_SetArrayValue($iID, $eMPB_cFgColour, Default) If $vBgColour = Default Then $vBgColour = __MPB_SetArrayValue($iID, $eMPB_cBgColour, Default) ;~ $bType = $eMPB_vTypeMarquee ; set the values for the function parameters __MPB_SetArrayValue($iID, $eMPB_cFgColour, __MPB_ConvertToARGB($vFgColour)) ;_ front colour __MPB_SetArrayValue($iID, $eMPB_cBgColour, __MPB_ConvertToARGB($vBgColour)) ;_ back colour __MPB_SetArrayValue($iID, $eMPB_cType, $bType) ;_ progress bar type __MPB_SetArrayValue($iID, $eMPB_cShowPcent, $bShowPcent) ;_ show current percent in progress bar __MPB_SetArrayValue($iID, $eMPB_cStripe, $bStripe) ;_ add a stripe effect to the progress image __MPB_SetArrayValue($iID, $eMPB_cStripeDir, $iStripeDir) ;_ set the direction ther stripes are drawn _GDIPlus_Startup() ; initialise the GDI+ library If @error Then Return SetError(2, 0, __MPB_GetLastError(@extended, '_GDIPlus_Startup')) ; create the gdi resources Local $vResult = __MPB_CreateBackBmp($iID) ; $hBitmap If @error Then Return SetError(3, 0, $vResult) $vResult = __MPB_CreatePbarBmp($iID) ; $hBmp If @error Then Return SetError(4, 0, $vResult) $vResult = __MPB_CreatePens($iID) ; $hPen, $hPen2 If @error Then Return SetError(5, 0, $vResult) ; set some default text properties __MPB_SetArrayValue($iID, $eMPB_cText, Default) __MPB_SetArrayValue($iID, $eMPB_cTextFont, Default) __MPB_SetArrayValue($iID, $eMPB_cTextColour, Default) __MPB_SetArrayValue($iID, $eMPB_cTextStyle, Default) __MPB_SetArrayValue($iID, $eMPB_cTextAlign, Default) __MPB_SetArrayValue($iID, $eMPB_cTextFormat, $bShowPcent) ; reset current percentage value $__g_avPBars[$iID][$eMPB_cPcentVal] = 0 $vResult = __MPB_CreateLineBrush($iID) ; dcreate line brush If @error Then Return SetError(6, 0, $vResult) $vResult = __MPB_DrawString($iID) ; create string rectangle If @error Then Return SetError(7, 0, $vResult) ;~ _ArrayDisplay($__g_avPBars) __MPB_RefreshProgress($iID, 0) ;~ If $__g_avPBars[$iID][$eMPB_cType] = $eMPB_vTypeMarquee Then _GDIp_SetMarqueeSpeed($iID) ;~ ; start the callback timer that updates the progress bar Local $vRet = __MPB_InitProgressCallback() If @error Then Return SetError(7, 0, $vRet) Return SetError(0, 0, $iID) EndFunc ;==>_MPB_CreateProgress Func _MPB_SetProgressValue(ByRef $iID, $iPcent) If Not __MPB_ValidateProgressArray($iID) Then Return SetError(1, 0, 0) If $iPcent > 100 Then $iPcent = 100 If $iPcent < 0 Then $iPcent = 0 $__g_avPBars[$iID][$eMPB_cPcentVal] = $iPcent Return $iPcent EndFunc ;==>_MPB_SetProgressValue