Ebola57 Posted September 18 Share Posted September 18 (edited) Dear community I want to do a simple thing, that I need to be "fast" The simpliest way may occur clipping or eat too much ressources because of the frequencey of changes, so ... I wrote partially code and asked for the end to ChatGPT4o He helped on some points, but get definitely stuck (and stupid) on other, so here's my code _GetGradientColor($Value) returns a color in a 0-100% gradient as picture illustrates below _MyWinAPI_CreateIcon( $posX, $posY, $Color ) creates a rounded square filled with color retreived from _GetGradientColor($Value) ans set generic icons before GUISetState(@SW_SHOW, $hGUI) _MyWinAPI_UpdateIcon($idIcon, $Color) retrives the id of the icon ands "should" change its color, but either it does not. It sounds to be a bad handling of objects but I am unable to figure it. Here's full code with functions dans GUI example expandcollapse popup#include <StaticConstants.au3> #include "C:\Program Files (x86)\AutoIt3\Examples\Helpfile\Extras\WM_NOTIFY.au3" #include <GuiButton.au3> #include <WinAPIGdi.au3> #include <GUIConstantsEx.au3> Func _GetGradientColor($Value) ; Limit the value to the range [0, 100] If $Value < 0 Or $Value > 100 Then Return SetError(1, 0, 0) Local $Red = 0, $Green = 0, $Blue = 0 ; Gradient from pure red to pure orange (0-25%) If $Value <= 25 Then $Red = 255 $Green = Int(255 * ($Value / 25)) $Blue = 0 ; Gradient from pure orange to pure yellow (26-40%) ElseIf $Value <= 40 Then $Red = 255 $Green = 255 $Blue = 0 ; Gradient from pure yellow to pure green (41-50%) ElseIf $Value <= 50 Then $Red = 255 - Int(255 * (($Value - 40) / 10)) $Green = 255 $Blue = 0 ; Gradient from pure green to pure cyan (51-80%) ElseIf $Value <= 80 Then $Red = 0 $Green = 255 $Blue = Int(255 * (($Value - 50) / 30)) ; Gradient from pure cyan to pure blue (81-100%) Else $Red = 0 $Green = Int(255 - (255 * (($Value - 80) / 20))) $Blue = 255 EndIf ; Return the color in BGR format (for AutoIt) Return "0x" & Hex($Blue, 2) & Hex($Green, 2) & Hex($Red, 2) EndFunc Func _MyWinAPI_UpdateIcon($idIcon, $Color) ; Size and other parameters Local $cornerRadius = 7, $Size = 15 ; Get the handle of the existing Pic control Local $hPic = GUICtrlGetHandle($idIcon) ; Create a new compatible bitmap Local $hDev = _WinAPI_GetDC($hPic) Local $hDC = _WinAPI_CreateCompatibleDC($hDev) Local $hSource = _WinAPI_CreateCompatibleBitmapEx($hDev, $Size, $Size, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE))) Local $hSv = _WinAPI_SelectObject($hDC, $hSource) ; Create a brush for the background of the box Local $hBrush = _WinAPI_CreateSolidBrush($Color) Local $hOldBrush = _WinAPI_SelectObject($hDC, $hBrush) ; Create a pen to draw the outline Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, $Color) Local $hOldPen = _WinAPI_SelectObject($hDC, $hPen) ; Draw the rounded rectangle Local $tRECT = _WinAPI_CreateRect(0, 0, $Size, $Size) _WinAPI_RoundRect($hDC, $tRECT, $cornerRadius, $cornerRadius) ; Reset the old brush and pen _WinAPI_SelectObject($hDC, $hOldBrush) _WinAPI_DeleteObject($hBrush) _WinAPI_SelectObject($hDC, $hOldPen) _WinAPI_DeleteObject($hPen) ; Update the Pic control image GUICtrlSetImage($idIcon, $hSource) ; Clean up resources _WinAPI_SelectObject($hDC, $hSv) _WinAPI_DeleteDC($hDC) _WinAPI_ReleaseDC($hPic, $hDev) ; Free the previous bitmap Return $idIcon EndFunc Func _MyWinAPI_CreateIcon( $posX, $posY, $Color ) Local $cornerRadius = 7, $Size = 15 ; Create a Pic control to draw the rounded box Local $idIcon = GUICtrlCreatePic ('', $posX, $posY, $Size, $Size ) Local $hPic = GUICtrlGetHandle ( $idIcon ) ; Create a compatible bitmap Local $hDev = _WinAPI_GetDC ( $hPic ) Local $hDC = _WinAPI_CreateCompatibleDC ( $hDev ) Local $hSource = _WinAPI_CreateCompatibleBitmapEx($hDev, $Size, $Size, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE))) Local $hSv = _WinAPI_SelectObject ( $hDC, $hSource ) ; Create a brush for the background of the box Local $hBrush = _WinAPI_CreateSolidBrush ( $Color ) Local $hOldBrush = _WinAPI_SelectObject ( $hDC, $hBrush ) ; Create a pen to draw the outline Local $hPen = _WinAPI_CreatePen ( $PS_SOLID, 1, $Color ) Local $hOldPen = _WinAPI_SelectObject ( $hDC, $hPen ) ; Draw the rounded rectangle Local $tRECT = _WinAPI_CreateRect (0, 0, $Size, $Size ) _WinAPI_RoundRect ( $hDC, $tRECT, $cornerRadius, $cornerRadius ) ; Reset the old brushes and pens _WinAPI_SelectObject ( $hDC, $hOldBrush ) _WinAPI_DeleteObject ( $hBrush ) _WinAPI_SelectObject ( $hDC, $hOldPen ) _WinAPI_DeleteObject ( $hPen ) ; Add the image to the control _SendMessage ( $hPic, $STM_SETIMAGE, 0, $hSource ) _WinAPI_SelectObject ( $hDC, $hSv ) _WinAPI_DeleteDC ( $hDC ) ; Release the resources _WinAPI_ReleaseDC ( $hPic, $hDev ) Return SetError ( @error, @extended, $idIcon ) EndFunc ; Create the main GUI window Global $hGUI = GUICreate("Test color change of icons", 400, 300) GUISetBkColor(0x252525) ; Create a button to change the icon color Global $idButton = GUICtrlCreateButton("Change Icon Color", 150, 200, 100, 30) ; Create an initial icon Global $idIcon = _MyWinAPI_CreateIcon(150, 100, _GetGradientColor(50)) ; Show the GUI GUISetState(@SW_SHOW, $hGUI) ; Main loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton ; Generate a random value between 1 and 100 Local $RandomValue = Random(1, 100, 1) ; Get the new color Local $NewColor = _GetGradientColor($RandomValue) ; Update the existing icon's color _MyWinAPI_UpdateIcon(GUICtrlGetHandle($idIcon), $NewColor) GUISetState(@SW_SHOW, $hGUI) EndSwitch WEnd Any help would greatly appreciated, WinAPI is somehow at border at my knowledges, but I ma still ready ty learn Regards Edited September 18 by Ebola57 Link to comment Share on other sites More sharing options...
ioa747 Posted September 19 Share Posted September 19 (edited) ; Update the Pic control image ; GUICtrlSetImage($idIcon, $hSource) ; GUICtrlSetImage works with image files (not handles) ** ; Update the Pic control image using _SendMessage instead of GUICtrlSetImage _SendMessage($hPic, $STM_SETIMAGE, 0, $hSource) Edited September 19 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
pixelsearch Posted September 19 Share Posted September 19 (edited) I have a result using this instruction in the update function : _WinAPI_DrawBitmap At least it updates and changes the color of the picture control but I'm not satisfied. I wish @UEZ reads this and brings his expertise, he'll explain in a glance what should be done to solve your issue. By the way, something needs to be changed in the script : _MyWinAPI_UpdateIcon(GUICtrlGetHandle($idIcon), $NewColor) ; $idIcon should be passed, not its handle Func _MyWinAPI_UpdateIcon($idIcon, $Color) ... ConsoleWrite("$idIcon = " & $idIcon & @crlf) ; $idIcon = 0x006C078E (?) <=========== ; Get the handle of the existing Pic control Local $hPic = GUICtrlGetHandle($idIcon) ConsoleWrite("$idIcon = " & $idIcon & " $hPic = " & $hPic & @crlf) ; $idIcon = 0x006C078E $hPic = 0 (??) Good luck @ioa747 In my tests, _SendMessage() wasn't enough and didn't update the pic control. Only _WinAPI_DrawBitmap coupled with _SendMessage updated the control. Edited September 19 by pixelsearch Ebola57 1 Link to comment Share on other sites More sharing options...
Solution ioa747 Posted September 19 Solution Share Posted September 19 (edited) with these add it works ; Update the Pic control image using _SendMessage instead of GUICtrlSetImage _SendMessage($hPic, $STM_SETIMAGE, 0, $hSource) in Case $idButton ; Update the existing icon's color _MyWinAPI_UpdateIcon($idIcon, $NewColor) _WinAPI_RedrawWindow(GUICtrlGetHandle($idIcon)) ;** Edit: during the tests I did I forgot that I added the _WinAPI_RedrawWindow(GUICtrlGetHandle($idIcon)) after _MyWinAPI_UpdateIcon($idIcon, $NewColor) Edited September 19 by ioa747 pixelsearch, Ebola57 and Werty 3 I know that I know nothing Link to comment Share on other sites More sharing options...
Ebola57 Posted September 19 Author Share Posted September 19 (edited) Thank you both so much for responding so quickly ! Second post of @ioa747 works perfectly and is clearly fast ! 0.4ms far below my expactations 😁 So simple code, when you master the thing. Edited September 19 by Ebola57 ioa747 and pixelsearch 2 Link to comment Share on other sites More sharing options...
pixelsearch Posted September 19 Share Posted September 19 Glad you made it, _WinAPI_RedrawWindow added by ioa747 refreshed the control nicely We could combine both functions (create & update) in a single one, as they got plenty of code in common, for example : expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPIGdi.au3> #include <WinAPISysInternals.au3> #include <WindowsConstants.au3> ; Create the main GUI window GUICreate("Test color change of icons", 400, 300) GUISetBkColor(0x252525) ; blackish ; Create a button to change the icon color Global $idButton = GUICtrlCreateButton("Change Icon Color", 150, 200, 100, 30) ; Create a Pic control to draw the rounded box Global $Size = 15 Global $hPic = GUICtrlGetHandle ( GUICtrlCreatePic ('', 150, 100, $Size, $Size ) ) ; Create an initial icon _MyWinAPI_UpdateIcon(_GetGradientColor(50)) ; green ; Show the GUI GUISetState(@SW_SHOW) ; Main loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton ; Generate a random value between 1 and 100 Local $RandomValue = Random(1, 100, 1) ; Get the new color Local $NewColor = _GetGradientColor($RandomValue) ; Update the existing icon's color _MyWinAPI_UpdateIcon($NewColor) _WinAPI_RedrawWindow($hPic) EndSwitch WEnd ;============================================== Func _GetGradientColor($Value) ; Limit the value to the range [0, 100] If $Value < 0 Or $Value > 100 Then Return SetError(1, 0, 0) Local $Red = 0, $Green = 0, $Blue = 0 ; Gradient from pure red to pure orange (0-25%) If $Value <= 25 Then $Red = 255 $Green = Int(255 * ($Value / 25)) $Blue = 0 ; Gradient from pure orange to pure yellow (26-40%) ElseIf $Value <= 40 Then $Red = 255 $Green = 255 $Blue = 0 ; Gradient from pure yellow to pure green (41-50%) ElseIf $Value <= 50 Then $Red = 255 - Int(255 * (($Value - 40) / 10)) $Green = 255 $Blue = 0 ; Gradient from pure green to pure cyan (51-80%) ElseIf $Value <= 80 Then $Red = 0 $Green = 255 $Blue = Int(255 * (($Value - 50) / 30)) ; Gradient from pure cyan to pure blue (81-100%) Else $Red = 0 $Green = Int(255 - (255 * (($Value - 80) / 20))) $Blue = 255 EndIf ; Return the color in BGR format (for AutoIt) Return "0x" & Hex($Blue, 2) & Hex($Green, 2) & Hex($Red, 2) EndFunc ;============================================== Func _MyWinAPI_UpdateIcon( $Color ) Local $cornerRadius = 7 ; Create a compatible bitmap Local $hDev = _WinAPI_GetDC ( $hPic ) Local $hDC = _WinAPI_CreateCompatibleDC ( $hDev ) Local $hSource = _WinAPI_CreateCompatibleBitmapEx($hDev, $Size, $Size, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE))) Local $hSv = _WinAPI_SelectObject ( $hDC, $hSource ) ; Create a brush for the background of the box Local $hBrush = _WinAPI_CreateSolidBrush ( $Color ) Local $hOldBrush = _WinAPI_SelectObject ( $hDC, $hBrush ) ; Create a pen to draw the outline Local $hPen = _WinAPI_CreatePen ( $PS_SOLID, 1, $Color ) Local $hOldPen = _WinAPI_SelectObject ( $hDC, $hPen ) ; Draw the rounded rectangle Local $tRECT = _WinAPI_CreateRect (0, 0, $Size, $Size ) _WinAPI_RoundRect ( $hDC, $tRECT, $cornerRadius, $cornerRadius ) ; Add the image to the control _SendMessage ( $hPic, $STM_SETIMAGE, 0, $hSource ) Local $hObj = _SendMessage($hPic, $STM_GETIMAGE) If $hObj <> $hSource Then _WinAPI_DeleteObject($hSource) ; Reset the old brushes and pens (originals) _WinAPI_SelectObject ( $hDC, $hOldBrush ) _WinAPI_DeleteObject ( $hBrush ) _WinAPI_SelectObject ( $hDC, $hOldPen ) _WinAPI_DeleteObject ( $hPen ) ; Release the resources _WinAPI_SelectObject ( $hDC, $hSv ) ; reset original context _WinAPI_ReleaseDC ( $hPic, $hDev ) _WinAPI_DeleteDC ( $hDC ) EndFunc ioa747 and Werty 2 Link to comment Share on other sites More sharing options...
Werty Posted September 19 Share Posted September 19 (edited) Maybe just build an array with the gradient values that runs once when the script is started and use it as a lookup table, no need to do the calculations all the time, there is only 101 of them that doesnt change, always the same, better yet, just hardcode them in and get rid of the _GetGradientColor() function, greener and more CO² friendly and sligthly faster. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPIGdi.au3> #include <WinAPISysInternals.au3> #include <WindowsConstants.au3> Global $GradientColor[101] = [0x0000FF,0x000AFF,0x0014FF,0x001EFF,0x0028FF,0x0033FF,0x003DFF,0x0047FF,0x0051FF,0x005BFF, _ 0x0066FF,0x0070FF,0x007AFF,0x0084FF,0x008EFF,0x0099FF,0x00A3FF,0x00ADFF,0x00B7FF,0x00C1FF, _ 0x00CCFF,0x00D6FF,0x00E0FF,0x00EAFF,0x00F4FF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF, _ 0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF, _ 0x00FFFF,0x00FFE6,0x00FFCC,0x00FFB3,0x00FF99,0x00FF80,0x00FF66,0x00FF4D,0x00FF33,0x00FF1A, _ 0x00FF00,0x08FF00,0x11FF00,0x19FF00,0x22FF00,0x2AFF00,0x33FF00,0x3BFF00,0x44FF00,0x4CFF00, _ 0x55FF00,0x5DFF00,0x66FF00,0x6EFF00,0x77FF00,0x7FFF00,0x88FF00,0x90FF00,0x99FF00,0xA1FF00, _ 0xAAFF00,0xB2FF00,0xBBFF00,0xC3FF00,0xCCFF00,0xD4FF00,0xDDFF00,0xE5FF00,0xEEFF00,0xF6FF00, _ 0xFFFF00,0xFFF200,0xFFE500,0xFFD800,0xFFCC00,0xFFBF00,0xFFB200,0xFFA500,0xFF9900,0xFF8C00, _ 0xFF7F00,0xFF7200,0xFF6600,0xFF5900,0xFF4C00,0xFF3F00,0xFF3300,0xFF2600,0xFF1900,0xFF0C00, _ 0xFF0000] ; Create the main GUI window GUICreate("Test color change of icons", 400, 300) GUISetBkColor(0x252525) ; blackish ; Create a button to change the icon color Global $idButton = GUICtrlCreateButton("Change Icon Color", 150, 200, 100, 30) ; Create a Pic control to draw the rounded box Global $Size = 15 Global $hPic = GUICtrlGetHandle ( GUICtrlCreatePic ('', 150, 100, $Size, $Size ) ) ; Create an initial icon _MyWinAPI_UpdateIcon($GradientColor[50]) ; green ; Show the GUI GUISetState(@SW_SHOW) ; Main loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton ; Generate a random value between 1 and 100 Local $RandomValue = Random(1, 100, 1) ; Get the new color Local $NewColor = $GradientColor[$RandomValue] ; Update the existing icon's color _MyWinAPI_UpdateIcon($NewColor) _WinAPI_RedrawWindow($hPic) EndSwitch WEnd ;============================================== Func _MyWinAPI_UpdateIcon( $Color ) Local $cornerRadius = 7 ; Create a compatible bitmap Local $hDev = _WinAPI_GetDC ( $hPic ) Local $hDC = _WinAPI_CreateCompatibleDC ( $hDev ) Local $hSource = _WinAPI_CreateCompatibleBitmapEx($hDev, $Size, $Size, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE))) Local $hSv = _WinAPI_SelectObject ( $hDC, $hSource ) ; Create a brush for the background of the box Local $hBrush = _WinAPI_CreateSolidBrush ( $Color ) Local $hOldBrush = _WinAPI_SelectObject ( $hDC, $hBrush ) ; Create a pen to draw the outline Local $hPen = _WinAPI_CreatePen ( $PS_SOLID, 1, $Color ) Local $hOldPen = _WinAPI_SelectObject ( $hDC, $hPen ) ; Draw the rounded rectangle Local $tRECT = _WinAPI_CreateRect (0, 0, $Size, $Size ) _WinAPI_RoundRect ( $hDC, $tRECT, $cornerRadius, $cornerRadius ) ; Add the image to the control _SendMessage ( $hPic, $STM_SETIMAGE, 0, $hSource ) Local $hObj = _SendMessage($hPic, $STM_GETIMAGE) If $hObj <> $hSource Then _WinAPI_DeleteObject($hSource) ; Reset the old brushes and pens (originals) _WinAPI_SelectObject ( $hDC, $hOldBrush ) _WinAPI_DeleteObject ( $hBrush ) _WinAPI_SelectObject ( $hDC, $hOldPen ) _WinAPI_DeleteObject ( $hPen ) ; Release the resources _WinAPI_SelectObject ( $hDC, $hSv ) ; reset original context _WinAPI_ReleaseDC ( $hPic, $hDev ) _WinAPI_DeleteDC ( $hDC ) EndFunc Btw, isnt something missing here... ; Gradient from pure orange to pure yellow (26-40%) ElseIf $Value <= 40 Then $Red = 255 $Green = 255 $Blue = 0 Edited September 19 by Werty pixelsearch, Ebola57 and ioa747 3 Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Ebola57 Posted September 20 Author Share Posted September 20 15 hours ago, pixelsearch said: Glad you made it, _WinAPI_RedrawWindow added by ioa747 refreshed the control nicely We could combine both functions (create & update) in a single one, as they got plenty of code in common, for example : [...] I will carefully read your codes, and get the best benefit of it Link to comment Share on other sites More sharing options...
Ebola57 Posted September 20 Author Share Posted September 20 10 hours ago, Werty said: Maybe just build an array with the gradient values that runs once when the script is started and use it as a lookup table, no need to do the calculations all the time, there is only 101 of them that doesnt change, always the same, better yet, just hardcode them in and get rid of the _GetGradientColor() function, greener and more CO² friendly and sligthly faster. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPIGdi.au3> #include <WinAPISysInternals.au3> #include <WindowsConstants.au3> Global $GradientColor[101] = [0x0000FF,0x000AFF,0x0014FF,0x001EFF,0x0028FF,0x0033FF,0x003DFF,0x0047FF,0x0051FF,0x005BFF, _ 0x0066FF,0x0070FF,0x007AFF,0x0084FF,0x008EFF,0x0099FF,0x00A3FF,0x00ADFF,0x00B7FF,0x00C1FF, _ 0x00CCFF,0x00D6FF,0x00E0FF,0x00EAFF,0x00F4FF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF, _ 0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF,0x00FFFF, _ 0x00FFFF,0x00FFE6,0x00FFCC,0x00FFB3,0x00FF99,0x00FF80,0x00FF66,0x00FF4D,0x00FF33,0x00FF1A, _ 0x00FF00,0x08FF00,0x11FF00,0x19FF00,0x22FF00,0x2AFF00,0x33FF00,0x3BFF00,0x44FF00,0x4CFF00, _ 0x55FF00,0x5DFF00,0x66FF00,0x6EFF00,0x77FF00,0x7FFF00,0x88FF00,0x90FF00,0x99FF00,0xA1FF00, _ 0xAAFF00,0xB2FF00,0xBBFF00,0xC3FF00,0xCCFF00,0xD4FF00,0xDDFF00,0xE5FF00,0xEEFF00,0xF6FF00, _ 0xFFFF00,0xFFF200,0xFFE500,0xFFD800,0xFFCC00,0xFFBF00,0xFFB200,0xFFA500,0xFF9900,0xFF8C00, _ 0xFF7F00,0xFF7200,0xFF6600,0xFF5900,0xFF4C00,0xFF3F00,0xFF3300,0xFF2600,0xFF1900,0xFF0C00, _ 0xFF0000] ; Create the main GUI window GUICreate("Test color change of icons", 400, 300) GUISetBkColor(0x252525) ; blackish ; Create a button to change the icon color Global $idButton = GUICtrlCreateButton("Change Icon Color", 150, 200, 100, 30) ; Create a Pic control to draw the rounded box Global $Size = 15 Global $hPic = GUICtrlGetHandle ( GUICtrlCreatePic ('', 150, 100, $Size, $Size ) ) ; Create an initial icon _MyWinAPI_UpdateIcon($GradientColor[50]) ; green ; Show the GUI GUISetState(@SW_SHOW) ; Main loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton ; Generate a random value between 1 and 100 Local $RandomValue = Random(1, 100, 1) ; Get the new color Local $NewColor = $GradientColor[$RandomValue] ; Update the existing icon's color _MyWinAPI_UpdateIcon($NewColor) _WinAPI_RedrawWindow($hPic) EndSwitch WEnd ;============================================== Func _MyWinAPI_UpdateIcon( $Color ) Local $cornerRadius = 7 ; Create a compatible bitmap Local $hDev = _WinAPI_GetDC ( $hPic ) Local $hDC = _WinAPI_CreateCompatibleDC ( $hDev ) Local $hSource = _WinAPI_CreateCompatibleBitmapEx($hDev, $Size, $Size, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE))) Local $hSv = _WinAPI_SelectObject ( $hDC, $hSource ) ; Create a brush for the background of the box Local $hBrush = _WinAPI_CreateSolidBrush ( $Color ) Local $hOldBrush = _WinAPI_SelectObject ( $hDC, $hBrush ) ; Create a pen to draw the outline Local $hPen = _WinAPI_CreatePen ( $PS_SOLID, 1, $Color ) Local $hOldPen = _WinAPI_SelectObject ( $hDC, $hPen ) ; Draw the rounded rectangle Local $tRECT = _WinAPI_CreateRect (0, 0, $Size, $Size ) _WinAPI_RoundRect ( $hDC, $tRECT, $cornerRadius, $cornerRadius ) ; Add the image to the control _SendMessage ( $hPic, $STM_SETIMAGE, 0, $hSource ) Local $hObj = _SendMessage($hPic, $STM_GETIMAGE) If $hObj <> $hSource Then _WinAPI_DeleteObject($hSource) ; Reset the old brushes and pens (originals) _WinAPI_SelectObject ( $hDC, $hOldBrush ) _WinAPI_DeleteObject ( $hBrush ) _WinAPI_SelectObject ( $hDC, $hOldPen ) _WinAPI_DeleteObject ( $hPen ) ; Release the resources _WinAPI_SelectObject ( $hDC, $hSv ) ; reset original context _WinAPI_ReleaseDC ( $hPic, $hDev ) _WinAPI_DeleteDC ( $hDC ) EndFunc Btw, isnt something missing here... ; Gradient from pure orange to pure yellow (26-40%) ElseIf $Value <= 40 Then $Red = 255 $Green = 255 $Blue = 0 Well, you're abslotuley right, most of my code and this part included is not optimised at all. The purpose is a home run in agil method to see if I can reach my goal fast. As soon as it will be done, I will start optimisations I had by the past some issues working wiht very large arrays, it frightened me a bit vs brute force CPU, but for 100 values it's indeed worth it. I d'ont know exactly if code is wirght, I tweaked it with ChatGPT to offset the colors, this is not a regular color scale. I shrinked the green and the yellow and tried to avoid cyan for some visual perceptions workarounds 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