TanerJames Posted December 14, 2020 Share Posted December 14, 2020 (edited) Hi, I don't know GDI plus Can we make the corners of the progress bar ellipse and outer contours? Thanks. expandcollapse popup;coded by UEZ build 2013-08-15 #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPISys.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172; $IMAGE_BITMAP = 0 Global $iW = 400, $iH = 25, $iBGColor = 0xFFFFFF Global Const $hGUI = GUICreate("Strip Progressbar", 600, 100) GUISetBkColor(0x404040) Global Const $iPic = GUICtrlCreatePic("", 150, 37, $iW, $iH) GUICtrlSetState(-1, $GUI_DISABLE) Global $iBtn = GUICtrlCreateButton("Start", 40, 20, 60, 60) GUISetState() Global $hHBmp_BG, $hB, $iSleep = 30 Global $fPerc, $fPercPrev, $iLoop, $aPos, $iPosX, $iPosY Global $aColors[7][2] = [[0xFFEE5F5B, 0xFFF07673],[0xFFABCC04, 0xFFBBD636],[0xFF78CCEE, 0xFF93D6F1],[0xFFFFBB58, 0xFFFFC97A],[0xFFFF6677, 0xFFFF8795],[0xFF78CCEE, 0xFFFFC97A],[0xFF78CCEE, 0xe8e5d9]] Global $iRandom, $iColorTP, $hTooltip _Init() Global $iDeltaX = _WinAPI_GetSystemMetrics(7) Global $iDeltaY = _WinAPI_GetSystemMetrics(4) + _WinAPI_GetSystemMetrics(33) Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ToolTip("") GUIRegisterMsg($WM_TIMER, "") _WinAPI_DeleteObject($hHBmp_BG) _GDIPlus_Shutdown() GUIDelete() Exit Case $iBtn $fPerc = 0 $iRandom = Random(0, UBound($aColors) - 1, 1) $iColorTP = BitShift(BitAND(BitAND(0x00FFFFFF, $aColors[$iRandom][1]), 0xFF), -16) + BitAND(0x0000FF00, $aColors[$iRandom][1]) + BitShift(BitAND(BitAND(0x00FFFFFF, $aColors[$iRandom][1]), 0xFF0000), 16) ;convert to BGR GUIRegisterMsg($WM_TIMER, "PlayAnim") DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iSleep, "int", 0) EndSwitch Until False Func _Init() $hHBmp_BG = _GDIPlus_StripProgressbar(0, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], "") $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hHBmp_BG) EndFunc ;==>_Init Func PlayAnim() Local $sText = "Loading...", $i, $iCalc1, $iCalc2 $fPerc += 0.5 If $fPerc >= 100.5 Then GUIRegisterMsg($WM_TIMER, "") $sText = "Done" EndIf $iLoop = $fPerc - $fPercPrev $fPercPrev = $fPerc For $i = $iLoop To 0 Step - 1 $iCalc1 = ($fPerc - $i) $hHBmp_BG = _GDIPlus_StripProgressbar($iCalc1, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], $sText) $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hHBmp_BG) $aPosCtrl = ControlGetPos($hGUI, 0, $iPic) $aPosGUI = WinGetPos($hGUI) $iPosX = $aPosCtrl[0] + $aPosGUI[0] + $iDeltaX $iPosY = $aPosCtrl[1] + $aPosGUI[1] + $aPosCtrl[3] + $iDeltaY - 2 If $iCalc1 >= 100.5 Then $iCalc1 = 100 $iCalc2 = $iPosX + ($fPerc - $i) / 100 * $iW - 1 If $iCalc2 >= $iPosX + $iW Then $iCalc2 = $iPosX + $iW ToolTip(StringFormat("%02d %", $iCalc1), $iCalc2, $iPosY, "", "", 3) $hTooltip = WinGetHandle(StringFormat("%02d %", ($fPerc - $i))) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hTooltip, "wstr", "", "wstr", "") DllCall("user32.dll", "int", "SendMessage", "hwnd", $hTooltip, "int", 1043, "int", $iColorTP, "int", 0) Next If $fPerc >= 100.5 Then Sleep(750) ToolTip("") EndIf EndFunc ;==>PlayAnim Func _GDIPlus_StripProgressbar($fPerc, $iW, $iH, $iBgColorGui = 0xFFF0F0F0, $iFgColor = 0xFFEE5F5B, $iBGColor = 0xFFF07673, $sText = "Loading...", $iTextColor = 0x000000, $iDir = -1, $iSpeed = 1, $sFont = "Arial", $bFlip = False, $bHBitmap = True) If $fPerc < 0 Then $fPerc = 0 If $fPerc > 100 Then $fPerc = 100 Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) _GDIPlus_GraphicsClear($hCtxt, $iBgColorGui) Local $iWidth = $iH * 2, $iLen = $iWidth / 2, $iY Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iH) Local Const $hCtxt_Bmp = _GDIPlus_ImageGetGraphicsContext($hBmp) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Bmp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local $hPen = _GDIPlus_PenCreate($iFgColor), $iPenSize = Int($iH / 12) Local $hPen2 = _GDIPlus_PenCreate(0x50000000, $iPenSize) _GDIPlus_GraphicsClear($hCtxt_Bmp, $iBGColor) Local Static $iX = 0 For $iY = 0 To $iH - 1 Switch $iDir Case 1 _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY, $iY, $iX + $iY + $iLen, $iY, $hPen) _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY - 2 * $iLen, $iY, $iX + $iY - 1 * $iLen, $iY, $hPen) Case Else _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY, $iY, -$iX + $iY + $iLen, $iY, $hPen) _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY + 2 * $iLen, $iY, -$iX + $iY + 3 * $iLen, $iY, $hPen) EndSwitch Next Local $tPoint1 = DllStructCreate("float;float") Local $tPoint2 = DllStructCreate("float;float") DllStructSetData($tPoint1, 1, $iW / 2) ;x1 DllStructSetData($tPoint2, 1, $iW / 2) ;x2 Local $hLineBrush If $bFlip Then _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, 0, $iWidth, 0, $hPen2) DllStructSetData($tPoint1, 2, $iH / 3) ;y1 DllStructSetData($tPoint2, 2, $iH * 2 / 3) ;y2 $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0x00FFFFFF, "uint", 0xB0FFFFFF, "int", 0, "int*", 0) $hLineBrush = $hLineBrush[6] _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, $iH * 2 / 3 + 1, $iW, $iH / 3, $hLineBrush) Else _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, $iH - $iPenSize / 2, $iWidth, $iH - $iPenSize / 2, $hPen2) DllStructSetData($tPoint1, 2, 0) ;y1 DllStructSetData($tPoint2, 2, $iH / 3) ;y2 $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0xB0FFFFFF, "uint", 0x00FFFFFF, "int", 0, "int*", 0) $hLineBrush = $hLineBrush[6] _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, 0, $iW, $iH / 3, $hLineBrush) EndIf $iX = Mod($iX + $iSpeed, $iWidth) Local $hTextureBrush = _GDIPlus_TextureCreate($hBmp) _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $fPerc / 100 * $iW, $iH, $hTextureBrush) If $bFlip Then _GDIPlus_ImageRotateFlip($hBitmap, 6) _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, 4) Local $hBrush = _GDIPlus_BrushCreateSolid(0x40000000 + $iTextColor) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $hFont = _GDIPlus_FontCreate($hFamily, $iH * 3 / 5, 2) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_PenDispose($hPen2) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_GraphicsDispose($hCtxt_Bmp) _GDIPlus_BitmapDispose($hBmp) _GDIPlus_BrushDispose($hTextureBrush) _GDIPlus_BrushDispose($hLineBrush) If $bHBitmap Then Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBITMAP EndIf Return $hBitmap EndFunc ;==>_GDIPlus_StripProgressbar;coded by UEZ build 2013-08-15 Edited December 16, 2020 by TanerJames mLipok 1 Link to comment Share on other sites More sharing options...
funkey Posted December 16, 2020 Share Posted December 16, 2020 (edited) Easy way around without GDIPlus: expandcollapse popup;coded by UEZ build 2013-08-15 #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPISys.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172; $IMAGE_BITMAP = 0 Global $iW = 400, $iH = 25, $iBGColor = 0xFFFFFF Global Const $hGUI = GUICreate("Strip Progressbar", 600, 100) GUISetBkColor(0x404040) Global $iBtn = GUICtrlCreateButton("Start", 40, 20, 60, 60) #Region new from funkey Global Const $hHelp = GUICreate("", $iW, $iH, 150, 37, $WS_CHILD, 0, $hGui) Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW, $iH) _WinAPI_SetParent($hHelp, $hGui) Global $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20) _WinAPI_SetWindowRgn($hHelp, $hRgn) #EndRegion GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $hHelp) GUISetState(@SW_SHOW, $hGUI) Global $hHBmp_BG, $hB, $iSleep = 30 Global $fPerc, $fPercPrev, $iLoop, $aPos, $iPosX, $iPosY Global $aColors[7][2] = [[0xFFEE5F5B, 0xFFF07673],[0xFFABCC04, 0xFFBBD636],[0xFF78CCEE, 0xFF93D6F1],[0xFFFFBB58, 0xFFFFC97A],[0xFFFF6677, 0xFFFF8795],[0xFF78CCEE, 0xFFFFC97A],[0xFF78CCEE, 0xe8e5d9]] Global $iRandom, $iColorTP, $hTooltip _Init() Global $iDeltaX = _WinAPI_GetSystemMetrics(7) Global $iDeltaY = _WinAPI_GetSystemMetrics(4) + _WinAPI_GetSystemMetrics(33) Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ToolTip("") GUIRegisterMsg($WM_TIMER, "") _WinAPI_DeleteObject($hHBmp_BG) _GDIPlus_Shutdown() GUIDelete() Exit Case $iBtn $fPerc = 0 $iRandom = Random(0, UBound($aColors) - 1, 1) $iColorTP = BitShift(BitAND(BitAND(0x00FFFFFF, $aColors[$iRandom][1]), 0xFF), -16) + BitAND(0x0000FF00, $aColors[$iRandom][1]) + BitShift(BitAND(BitAND(0x00FFFFFF, $aColors[$iRandom][1]), 0xFF0000), 16) ;convert to BGR GUIRegisterMsg($WM_TIMER, "PlayAnim") DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iSleep, "int", 0) EndSwitch Until False Func _Init() $hHBmp_BG = _GDIPlus_StripProgressbar(0, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], "") $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hHBmp_BG) EndFunc ;==>_Init Func PlayAnim() Local $sText = "Loading...", $i, $iCalc1, $iCalc2 $fPerc += 0.5 If $fPerc >= 100.5 Then GUIRegisterMsg($WM_TIMER, "") $sText = "Done" EndIf $iLoop = $fPerc - $fPercPrev $fPercPrev = $fPerc For $i = $iLoop To 0 Step - 1 $iCalc1 = ($fPerc - $i) $hHBmp_BG = _GDIPlus_StripProgressbar($iCalc1, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], $sText) $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hHBmp_BG) $aPosCtrl = ControlGetPos($hGUI, 0, $iPic) $aPosGUI = WinGetPos($hGUI) $iPosX = $aPosCtrl[0] + $aPosGUI[0] + $iDeltaX $iPosY = $aPosCtrl[1] + $aPosGUI[1] + $aPosCtrl[3] + $iDeltaY - 2 If $iCalc1 >= 100.5 Then $iCalc1 = 100 $iCalc2 = $iPosX + ($fPerc - $i) / 100 * $iW - 1 If $iCalc2 >= $iPosX + $iW Then $iCalc2 = $iPosX + $iW ToolTip(StringFormat("%02d %", $iCalc1), $iCalc2, $iPosY, "", "", 3) $hTooltip = WinGetHandle(StringFormat("%02d %", ($fPerc - $i))) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hTooltip, "wstr", "", "wstr", "") DllCall("user32.dll", "int", "SendMessage", "hwnd", $hTooltip, "int", 1043, "int", $iColorTP, "int", 0) Next If $fPerc >= 100.5 Then Sleep(750) ToolTip("") EndIf EndFunc ;==>PlayAnim Func _GDIPlus_StripProgressbar($fPerc, $iW, $iH, $iBgColorGui = 0xFFF0F0F0, $iFgColor = 0xFFEE5F5B, $iBGColor = 0xFFF07673, $sText = "Loading...", $iTextColor = 0x000000, $iDir = -1, $iSpeed = 1, $sFont = "Arial", $bFlip = False, $bHBitmap = True) If $fPerc < 0 Then $fPerc = 0 If $fPerc > 100 Then $fPerc = 100 Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) _GDIPlus_GraphicsClear($hCtxt, $iBgColorGui) Local $iWidth = $iH * 2, $iLen = $iWidth / 2, $iY Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iH) Local Const $hCtxt_Bmp = _GDIPlus_ImageGetGraphicsContext($hBmp) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Bmp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local $hPen = _GDIPlus_PenCreate($iFgColor), $iPenSize = Int($iH / 12) Local $hPen2 = _GDIPlus_PenCreate(0x50000000, $iPenSize) _GDIPlus_GraphicsClear($hCtxt_Bmp, $iBGColor) Local Static $iX = 0 For $iY = 0 To $iH - 1 Switch $iDir Case 1 _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY, $iY, $iX + $iY + $iLen, $iY, $hPen) _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY - 2 * $iLen, $iY, $iX + $iY - 1 * $iLen, $iY, $hPen) Case Else _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY, $iY, -$iX + $iY + $iLen, $iY, $hPen) _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY + 2 * $iLen, $iY, -$iX + $iY + 3 * $iLen, $iY, $hPen) EndSwitch Next Local $tPoint1 = DllStructCreate("float;float") Local $tPoint2 = DllStructCreate("float;float") DllStructSetData($tPoint1, 1, $iW / 2) ;x1 DllStructSetData($tPoint2, 1, $iW / 2) ;x2 Local $hLineBrush If $bFlip Then _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, 0, $iWidth, 0, $hPen2) DllStructSetData($tPoint1, 2, $iH / 3) ;y1 DllStructSetData($tPoint2, 2, $iH * 2 / 3) ;y2 $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0x00FFFFFF, "uint", 0xB0FFFFFF, "int", 0, "int*", 0) $hLineBrush = $hLineBrush[6] _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, $iH * 2 / 3 + 1, $iW, $iH / 3, $hLineBrush) Else _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, $iH - $iPenSize / 2, $iWidth, $iH - $iPenSize / 2, $hPen2) DllStructSetData($tPoint1, 2, 0) ;y1 DllStructSetData($tPoint2, 2, $iH / 3) ;y2 $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0xB0FFFFFF, "uint", 0x00FFFFFF, "int", 0, "int*", 0) $hLineBrush = $hLineBrush[6] _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, 0, $iW, $iH / 3, $hLineBrush) EndIf $iX = Mod($iX + $iSpeed, $iWidth) Local $hTextureBrush = _GDIPlus_TextureCreate($hBmp) _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $fPerc / 100 * $iW, $iH, $hTextureBrush) If $bFlip Then _GDIPlus_ImageRotateFlip($hBitmap, 6) _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, 4) Local $hBrush = _GDIPlus_BrushCreateSolid(0x40000000 + $iTextColor) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $hFont = _GDIPlus_FontCreate($hFamily, $iH * 3 / 5, 2) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) _GDIPlus_StringFormatSetAlign($hFormat, 1) ;Center text _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush) ;Loading text _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_PenDispose($hPen2) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_GraphicsDispose($hCtxt_Bmp) _GDIPlus_BitmapDispose($hBmp) _GDIPlus_BrushDispose($hTextureBrush) _GDIPlus_BrushDispose($hLineBrush) If $bHBitmap Then Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBITMAP EndIf Return $hBitmap EndFunc ;==>_GDIPlus_StripProgressbar;coded by UEZ build 2013-08-15 Not ideal code part for border: #Region new from funkey Global Const $hHelp = GUICreate("", $iW + 16, $iH + 7, 150, 47, $WS_CHILD, 0, $hGui) GUISetBkColor(0x000000) Global Const $iPic = GUICtrlCreatePic("", 8, 3, $iW , $iH) _WinAPI_SetParent($hHelp, $hGui) Global $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iW + 16, $iH + 7, 20, 20) _WinAPI_SetWindowRgn($hHelp, $hRgn) #EndRegion Better solution for border: #Region new from funkey Global Const $hHelp1 = GUICreate("", $iW + 6, $iH + 6, 150, 47, $WS_CHILD, 0, $hGui) _WinAPI_SetParent($hHelp1, $hGui) GUISetBkColor(0x000000) Global Const $hHelp2 = GUICreate("", $iW, $iH, 3, 3, $WS_CHILD, 0, $hHelp1) _WinAPI_SetParent($hHelp2, $hHelp1) Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW , $iH) Global $hRgn1 = _WinAPI_CreateRoundRectRgn(0, 0, $iW + 6, $iH + 6, 25, 25) Global $hRgn2 = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20) _WinAPI_SetWindowRgn($hHelp1, $hRgn1) _WinAPI_SetWindowRgn($hHelp2, $hRgn2) #EndRegion Edited December 16, 2020 by funkey added code for border version Aelc and mLipok 1 1 Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
TanerJames Posted December 16, 2020 Author Share Posted December 16, 2020 11 hours ago, funkey said: Easy way around without GDIPlus: expandcollapse popup;coded by UEZ build 2013-08-15 #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPISys.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172; $IMAGE_BITMAP = 0 Global $iW = 400, $iH = 25, $iBGColor = 0xFFFFFF Global Const $hGUI = GUICreate("Strip Progressbar", 600, 100) GUISetBkColor(0x404040) Global $iBtn = GUICtrlCreateButton("Start", 40, 20, 60, 60) #Region new from funkey Global Const $hHelp = GUICreate("", $iW, $iH, 150, 37, $WS_CHILD, 0, $hGui) Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW, $iH) _WinAPI_SetParent($hHelp, $hGui) Global $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20) _WinAPI_SetWindowRgn($hHelp, $hRgn) #EndRegion GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $hHelp) GUISetState(@SW_SHOW, $hGUI) Global $hHBmp_BG, $hB, $iSleep = 30 Global $fPerc, $fPercPrev, $iLoop, $aPos, $iPosX, $iPosY Global $aColors[7][2] = [[0xFFEE5F5B, 0xFFF07673],[0xFFABCC04, 0xFFBBD636],[0xFF78CCEE, 0xFF93D6F1],[0xFFFFBB58, 0xFFFFC97A],[0xFFFF6677, 0xFFFF8795],[0xFF78CCEE, 0xFFFFC97A],[0xFF78CCEE, 0xe8e5d9]] Global $iRandom, $iColorTP, $hTooltip _Init() Global $iDeltaX = _WinAPI_GetSystemMetrics(7) Global $iDeltaY = _WinAPI_GetSystemMetrics(4) + _WinAPI_GetSystemMetrics(33) Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ToolTip("") GUIRegisterMsg($WM_TIMER, "") _WinAPI_DeleteObject($hHBmp_BG) _GDIPlus_Shutdown() GUIDelete() Exit Case $iBtn $fPerc = 0 $iRandom = Random(0, UBound($aColors) - 1, 1) $iColorTP = BitShift(BitAND(BitAND(0x00FFFFFF, $aColors[$iRandom][1]), 0xFF), -16) + BitAND(0x0000FF00, $aColors[$iRandom][1]) + BitShift(BitAND(BitAND(0x00FFFFFF, $aColors[$iRandom][1]), 0xFF0000), 16) ;convert to BGR GUIRegisterMsg($WM_TIMER, "PlayAnim") DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iSleep, "int", 0) EndSwitch Until False Func _Init() $hHBmp_BG = _GDIPlus_StripProgressbar(0, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], "") $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hHBmp_BG) EndFunc ;==>_Init Func PlayAnim() Local $sText = "Loading...", $i, $iCalc1, $iCalc2 $fPerc += 0.5 If $fPerc >= 100.5 Then GUIRegisterMsg($WM_TIMER, "") $sText = "Done" EndIf $iLoop = $fPerc - $fPercPrev $fPercPrev = $fPerc For $i = $iLoop To 0 Step - 1 $iCalc1 = ($fPerc - $i) $hHBmp_BG = _GDIPlus_StripProgressbar($iCalc1, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], $sText) $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hHBmp_BG) $aPosCtrl = ControlGetPos($hGUI, 0, $iPic) $aPosGUI = WinGetPos($hGUI) $iPosX = $aPosCtrl[0] + $aPosGUI[0] + $iDeltaX $iPosY = $aPosCtrl[1] + $aPosGUI[1] + $aPosCtrl[3] + $iDeltaY - 2 If $iCalc1 >= 100.5 Then $iCalc1 = 100 $iCalc2 = $iPosX + ($fPerc - $i) / 100 * $iW - 1 If $iCalc2 >= $iPosX + $iW Then $iCalc2 = $iPosX + $iW ToolTip(StringFormat("%02d %", $iCalc1), $iCalc2, $iPosY, "", "", 3) $hTooltip = WinGetHandle(StringFormat("%02d %", ($fPerc - $i))) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hTooltip, "wstr", "", "wstr", "") DllCall("user32.dll", "int", "SendMessage", "hwnd", $hTooltip, "int", 1043, "int", $iColorTP, "int", 0) Next If $fPerc >= 100.5 Then Sleep(750) ToolTip("") EndIf EndFunc ;==>PlayAnim Func _GDIPlus_StripProgressbar($fPerc, $iW, $iH, $iBgColorGui = 0xFFF0F0F0, $iFgColor = 0xFFEE5F5B, $iBGColor = 0xFFF07673, $sText = "Loading...", $iTextColor = 0x000000, $iDir = -1, $iSpeed = 1, $sFont = "Arial", $bFlip = False, $bHBitmap = True) If $fPerc < 0 Then $fPerc = 0 If $fPerc > 100 Then $fPerc = 100 Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) _GDIPlus_GraphicsClear($hCtxt, $iBgColorGui) Local $iWidth = $iH * 2, $iLen = $iWidth / 2, $iY Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iH) Local Const $hCtxt_Bmp = _GDIPlus_ImageGetGraphicsContext($hBmp) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Bmp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local $hPen = _GDIPlus_PenCreate($iFgColor), $iPenSize = Int($iH / 12) Local $hPen2 = _GDIPlus_PenCreate(0x50000000, $iPenSize) _GDIPlus_GraphicsClear($hCtxt_Bmp, $iBGColor) Local Static $iX = 0 For $iY = 0 To $iH - 1 Switch $iDir Case 1 _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY, $iY, $iX + $iY + $iLen, $iY, $hPen) _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY - 2 * $iLen, $iY, $iX + $iY - 1 * $iLen, $iY, $hPen) Case Else _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY, $iY, -$iX + $iY + $iLen, $iY, $hPen) _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY + 2 * $iLen, $iY, -$iX + $iY + 3 * $iLen, $iY, $hPen) EndSwitch Next Local $tPoint1 = DllStructCreate("float;float") Local $tPoint2 = DllStructCreate("float;float") DllStructSetData($tPoint1, 1, $iW / 2) ;x1 DllStructSetData($tPoint2, 1, $iW / 2) ;x2 Local $hLineBrush If $bFlip Then _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, 0, $iWidth, 0, $hPen2) DllStructSetData($tPoint1, 2, $iH / 3) ;y1 DllStructSetData($tPoint2, 2, $iH * 2 / 3) ;y2 $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0x00FFFFFF, "uint", 0xB0FFFFFF, "int", 0, "int*", 0) $hLineBrush = $hLineBrush[6] _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, $iH * 2 / 3 + 1, $iW, $iH / 3, $hLineBrush) Else _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, $iH - $iPenSize / 2, $iWidth, $iH - $iPenSize / 2, $hPen2) DllStructSetData($tPoint1, 2, 0) ;y1 DllStructSetData($tPoint2, 2, $iH / 3) ;y2 $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0xB0FFFFFF, "uint", 0x00FFFFFF, "int", 0, "int*", 0) $hLineBrush = $hLineBrush[6] _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, 0, $iW, $iH / 3, $hLineBrush) EndIf $iX = Mod($iX + $iSpeed, $iWidth) Local $hTextureBrush = _GDIPlus_TextureCreate($hBmp) _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $fPerc / 100 * $iW, $iH, $hTextureBrush) If $bFlip Then _GDIPlus_ImageRotateFlip($hBitmap, 6) _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, 4) Local $hBrush = _GDIPlus_BrushCreateSolid(0x40000000 + $iTextColor) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $hFont = _GDIPlus_FontCreate($hFamily, $iH * 3 / 5, 2) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) _GDIPlus_StringFormatSetAlign($hFormat, 1) ;Center text _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush) ;Loading text _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_PenDispose($hPen2) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_GraphicsDispose($hCtxt_Bmp) _GDIPlus_BitmapDispose($hBmp) _GDIPlus_BrushDispose($hTextureBrush) _GDIPlus_BrushDispose($hLineBrush) If $bHBitmap Then Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBITMAP EndIf Return $hBitmap EndFunc ;==>_GDIPlus_StripProgressbar;coded by UEZ build 2013-08-15 Not ideal code part for border: #Region new from funkey Global Const $hHelp = GUICreate("", $iW + 16, $iH + 7, 150, 47, $WS_CHILD, 0, $hGui) GUISetBkColor(0x000000) Global Const $iPic = GUICtrlCreatePic("", 8, 3, $iW , $iH) _WinAPI_SetParent($hHelp, $hGui) Global $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iW + 16, $iH + 7, 20, 20) _WinAPI_SetWindowRgn($hHelp, $hRgn) #EndRegion Better solution for border: #Region new from funkey Global Const $hHelp1 = GUICreate("", $iW + 6, $iH + 6, 150, 47, $WS_CHILD, 0, $hGui) _WinAPI_SetParent($hHelp1, $hGui) GUISetBkColor(0x000000) Global Const $hHelp2 = GUICreate("", $iW, $iH, 3, 3, $WS_CHILD, 0, $hHelp1) _WinAPI_SetParent($hHelp2, $hHelp1) Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW , $iH) Global $hRgn1 = _WinAPI_CreateRoundRectRgn(0, 0, $iW + 6, $iH + 6, 25, 25) Global $hRgn2 = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20) _WinAPI_SetWindowRgn($hHelp1, $hRgn1) _WinAPI_SetWindowRgn($hHelp2, $hRgn2) #EndRegion 👍 Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now