Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/20/2024 in all areas

  1. guys, a couple of hours ago I prepared an answer before yours, but I deleted it as it was too vehement. Now I'll rephrase it differently, focusing on the one and only important fact : @mr-es335 1) You used the FileExists function in your penultimate post, like this : In this case, the $Result variable you tested could be 0 or 1, as indicated in the help file, topic FileExists : FileExists : Return Value Success: 1. Failure: 0 if path/file does not exist. So far, so good. 2) In your last post, you're using the RegRead function in the same way, like this : Did you read the help file (topic RegRead) before asking "why it doesn't work" ? If you had read it, then you would have discovered by yourself that there is no $Result = 0 or 1 for RegRead Help file, topic RegRead : RegRead Return Value Success: the requested registry value. @extended is set to the type of the value $REG_... . These types are defined in the "Constants.au3" include file. Failure: sets the @error flag to non-zero. @error: 1 = unable to open requested key 2 = unable to open requested main key 3 = unable to remote connect to the registry -1 = unable to open requested value -2 = value type not supported So testing @error immediately after RegRead is the best way to check what's happening. My advice is you should always read the help file, for any function, to make sure that you check correctly : * The type of result that the function returns (RegRead will NEVER return 0 or 1) * The @error value (if indicated by the help file) to be checked asap (If not @error Then... ) and certainly not the type of line I see in one of your script : if @error <= 0 .... check it always <> 0, not <= Good luck
    2 points
  2. ioa747, Like "water" had stated previously, though not a direct quote, "K.I.S.S."... which may be interpreted as either, "Keep It Simple, Stupid!" ...or... "Keep It Stupidly Simple!" As to your two examples, ; Passes a single parameter to _DoesRegKeyExist _DoesRegKeyExist("HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5") ; ----------------------------------------------- Func _DoesRegKeyExist($sKeyname) ; Code EndFunc ;==>_DoesRegKeyExist ; ----------------------------------------------- ; Passes two parameters to _DoesRegValueExist _DoesRegValueExist("HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5", "InstallVSTDir") Func _DoesRegValueExist($sKeyname, $sValuename) ; Code EndFunc ;==>_DoesRegValueExist ; ----------------------------------------------- "Wow!", "Wow!..."Wow!" ...and.. "Wow!"..."Wow!..."Wow!" Thanks so very much, ioa747. Appreciated!
    1 point
  3. Acts432

    SmartNote

    Solution without accessing drive (except of running tesseract.exe). Whole operation is processed in memory. OCRScreenCaptureToText.au3 ;#Include <WinAPI.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> ;#include <WinAPIvkeysConstants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <Memory.au3> #Region --- Deklarácie  --- Global $sHotKeyEscFunction = "Terminate" Global Const $iMinInt32 = -2147483648 Local $hWndTaskManager = 0 #EndRegion --- Declarations --- #Region --- Program  --- Opt('WinWaitDelay', 100) Opt('WinDetectHiddenText', 1) Opt('MouseCoordMode', 2) Opt("PixelCoordMode", 2) HotKeySet("{ESC}", $sHotKeyEscFunction) ;Press Esc to terminate script Send("^+{ESC}") ;ShellExecute("Taskmgr.exe") $hWndTaskManager = WinWait("[CLASS:#32770]") WinActivate("[CLASS:#32770]") Local $sOutput = OCRScreenCaptureToText($hWndTaskManager, $iMinInt32, $iMinInt32, $iMinInt32, $iMinInt32, "eng", True, @ScriptDir & "\image.PNG") If @error Then     ErrorMsgBox(((@error = 3 And @extended = 1) ? "Stderr Read: " : "") & $sOutput & ' ' & @error & ' ' & @extended)     Exit 3 EndIf MsgBox($MB_SYSTEMMODAL, "OCRScreenCaptureToText", $sOutput) #EndRegion --- Program  --- #Region --- Functions  --- Func Terminate()     Exit 2 EndFunc Func ErrorMsgBox($text, $title = "Chyba")     Return MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), $title, $text) EndFunc ;======================================================================================================================================================================================= ; Description: ; Function OCRScreenCaptureToText provide OCR converting part of the screen or specified window to text ; ; Parameters: ; $hWnd - If not zero then corresponding window relative coordinates are used instead of absolute screen coordinates ; $iLeft, $iTop, $iRight, $iBottom - Coordinates of region to capture (if $iMinInt32 is specified then limit value will be used) ; $lang - Languages used in texts; You can combinate it as you need (E.g. "eng+deu+fra+ita+spa+por"); List of LangCode is available here: https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html ; $bShowPreview - If True then preview window of the captured region is shown ; $sFileName - If not empty string then captured region is saved into the file; File extension must be the same as $sFormat constant ; ; Please note: ; First you have to install tesseract (https://github.com/UB-Mannheim/tesseract/wiki) ; You can find proper installer here: https://digi.bib.uni-mannheim.de/tesseract/ ; I used this one: tesseract-ocr-w64-setup-5.4.0.20240606.exe (64-bit) ; Complete documentation is here: https://tesseract-ocr.github.io/tessdoc/ ; To increase the OCR precision try to enlarge the captured image to at least 300 DPI and check another options here: https://tesseract-ocr.github.io/tessdoc/ImproveQuality.html ;======================================================================================================================================================================================= Func OCRScreenCaptureToText($hWnd = 0, $iLeft = $iMinInt32, $iTop = $iMinInt32, $iRight = $iMinInt32, $iBottom = $iMinInt32, $lang = "eng", $bShowPreview = False, $sFileName = "")     ; Corrections of the coordinates     If $hWnd = 0 Then         If $iLeft = $iMinInt32 Or $iRight = $iMinInt32 Then             Local $XVirtualScreen = _WinAPI_GetSystemMetrics($SM_XVIRTUALSCREEN)             If $iLeft = $iMinInt32 Then $iLeft = $XVirtualScreen             If $iRight = $iMinInt32 Then $iRight = $XVirtualScreen + _WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN)         EndIf         If $iTop = $iMinInt32 Or $iBottom = $iMinInt32 Then             Local $YVirtualScreen = _WinAPI_GetSystemMetrics($SM_YVIRTUALSCREEN)             If $iTop = $iMinInt32 Then $iTop = $YVirtualScreen             If $iBottom = $iMinInt32 Then $iBottom = $YVirtualScreen + _WinAPI_GetSystemMetrics($SM_CYVIRTUALSCREEN)         EndIf         $hWnd = _WinAPI_GetDesktopWindow()     Else         If $iLeft = $iMinInt32 Then $iLeft = 0         If $iTop = $iMinInt32 Then $iTop = 0         If $iRight = $iMinInt32 Or $iBottom = $iMinInt32 Then             Local $aClientSize = WinGetClientSize($hWnd)             If $iRight = $iMinInt32 Then $iRight = $aClientSize[0]             If $iBottom = $iMinInt32 Then $iBottom = $aClientSize[1]         EndIf     EndIf     If $iRight < $iLeft Then Return SetError(1, 0, "Right cannot be less than Left")     If $iBottom < $iTop Then Return SetError(1, 1, "Bottom cannot be less than Top")              ; Capture the screen     Local $iWidth = $iRight - $iLeft     Local $iHeight = $iBottom - $iTop     Local $hDDC = _WinAPI_GetDC($hWnd)     Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight)     Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC)     _WinAPI_SelectObject($hCDC, $hBitmap)     _WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iHeight, $hDDC, $iLeft, $iTop, $SRCCOPY) ;normal colors ;    _WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iHeight, $hDDC, $iLeft, $iTop, $NOTSRCCOPY) ;invert colors     _WinAPI_DeleteDC($hCDC)     _WinAPI_ReleaseDC($hWnd, $hDDC)          ; Save the capture in memory as an image of specific format     Local Const $sFormat = "PNG"     _GDIPlus_Startup() ; Initialize GDI+ library     If @error Then Return SetError(2, 0, "_GDIPlus_Startup() - failed")     Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) ;convert GDI bitmap to GDI+ bitmap     _WinAPI_DeleteObject($hBitmap) ;release GDI bitmap resource because not needed anymore          ;convert to 4 BPP (it has good OCR results)     Local $hImageClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, _GDIPlus_ImageGetWidth($hImage), _GDIPlus_ImageGetHeight($hImage), $GDIP_PXF04INDEXED)     _GDIPlus_ImageDispose($hImage)     $hImage = $hImageClone          Switch $sFormat         Case "BMP", "GIF", "JPG", "JPEG", "PNG", "TIF", "TIFF"         Case Else             Return SetError(2, 2, "Unsupported image format")     EndSwitch     Local $sCLSID = _GDIPlus_EncodersGetCLSID($sFormat) ;create CLSID for a JPG image file type     If @error Then Return SetError(2, 3, "_GDIPlus_EncodersGetCLSID() - failed")     Local $tGUID = _WinAPI_GUIDFromString($sCLSID) ;convert CLSID GUID to binary form and returns $tagGUID structure     If @error Then Return SetError(2, 4, "_WinAPI_GUIDFromString() - failed")     Local $tParams     Switch $sFormat #comments-start         Case "BMP"             $tParams = 0             ; BMP format options:             ; $GDIP_PXF01INDEXED = 0x00030101: 1 bpp, indexed             ; $GDIP_PXF04INDEXED = 0x00030402: 4 bpp, indexed             ; $GDIP_PXF08INDEXED = 0x00030803: 8 bpp, indexed             ; $GDIP_PXF16GRAYSCALE = 0x00101004: 16 bpp, grayscale             ; $GDIP_PXF16RGB555 = 0x00021005: 16 bpp; 5 bits for each RGB             ; $GDIP_PXF16RGB565 = 0x00021006: 16 bpp; 5 bits red, 6 bits green, and 5 bits blue             ; $GDIP_PXF16ARGB1555 = 0x00061007: 16 bpp; 1 bit for alpha and 5 bits for each RGB component             ; $GDIP_PXF24RGB = 0x00021808: 24 bpp; 8 bits for each RGB             ; $GDIP_PXF32RGB = 0x00022009: 32 bpp; 8 bits for each RGB. No alpha.             ; $GDIP_PXF32ARGB = 0x0026200A: 32 bpp; 8 bits for each RGB and alpha             ; $GDIP_PXF32PARGB = 0x000E200B: 32 bpp; 8 bits for each RGB and alpha, pre-mulitiplied             ; $GDIP_PXF48RGB = 0x0010300C: 48 bpp; 16 bits for each RGB             ; $GDIP_PXF64ARGB = 0x0034400D: 64 bpp; 16 bits for each RGB and alpha             ; $GDIP_PXF64PARGB = 0x001A400E: 64 bpp; 16 bits for each RGB and alpha, pre-multiplied             Local $hImageClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, _GDIPlus_ImageGetWidth($hImage), _GDIPlus_ImageGetHeight($hImage), $GDIP_PXF24RGB)             _GDIPlus_ImageDispose($hImage)             $hImage = $hImageClone #comments-end         Case "JPG", "JPEG"             $tParams = _GDIPlus_ParamInit(1) ;initialize an encoder parameter list and return $tagGDIPENCODERPARAMS structure             Local $tData = DllStructCreate("int Quality") ;create struct to set JPG quality setting             DllStructSetData($tData, "Quality", 100) ; Quality option 0-100 (0: lowest, 100: highest)             _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($tData)) ;add a value to an encoder parameter list         Case "TIF", "TIFF"             $tParams = _GDIPlus_ParamInit(2) ;initialize an encoder parameter list and return $tagGDIPENCODERPARAMS structure             Local $tData = DllStructCreate("int ColorDepth;int Compression") ;create struct to set TIF quality setting             ; TIFF color depth options:             ; 24             ; 32             DllStructSetData($tData, "ColorDepth", 32)             ; TIFF compression options:             ; $GDIP_EVTCOMPRESSIONLZW = 2: LZW compression             ; $GDIP_EVTCOMPRESSIONCCITT3 = 3: CCITT3 compression             ; $GDIP_EVTCOMPRESSIONCCITT4 = 4: CCITT4 compression             ; $GDIP_EVTCOMPRESSIONRLE = 5: RLE compression             ; $GDIP_EVTCOMPRESSIONNONE = 6: No compression             DllStructSetData($tData, "Compression", $GDIP_EVTCOMPRESSIONLZW)             _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOLORDEPTH, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "ColorDepth")) ;add a value to an encoder parameter list             _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOMPRESSION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Compression")) ;add a value to an encoder parameter list         Case Else             $tParams = 0     EndSwitch     If $sFileName <> "" Then         If StringUpper(__GDIPlus_ExtractFileExt($sFileName)) <> $sFormat Then Return SetError(1, 2, "File extension differ from image format")         _GDIPlus_ImageSaveToFileEx($hImage, $sFileName, $sCLSID, IsDllStruct($tParams) ? $tParams : 0) ;save image as a file         If @error Then Return SetError(1, 3, "_GDIPlus_ImageSaveToFileEx() - failed")     EndIf     Local $pStream = _WinAPI_CreateStreamOnHGlobal() ;create stream (http://msdn.microsoft.com/en-us/library/ms864401.aspx)     If @error Then Return SetError(2, 5, "_WinAPI_CreateStreamOnHGlobal() - failed")     _GDIPlus_ImageSaveToStream($hImage, $pStream, $tGUID, $tParams) ;save the formatted bitmap in memory     If @error Then Return SetError(2, 6, "_GDIPlus_ImageSaveToStream() - failed")     _GDIPlus_ImageDispose($hImage)     If $bShowPreview Then         Local $tPoint = DllStructCreate("int X;int Y")         DllStructSetData($tPoint, "X", $iLeft)         DllStructSetData($tPoint, "Y", $iTop)         _WinAPI_ClientToScreen($hWnd, $tPoint)         Local $hWndPreview = GUICreate("Preview...", $iWidth, $iHeight, DllStructGetData($tPoint, "X") - _WinAPI_GetSystemMetrics($SM_CXFIXEDFRAME), DllStructGetData($tPoint, "Y") - _WinAPI_GetSystemMetrics($SM_CYFIXEDFRAME) - _WinAPI_GetSystemMetrics($SM_CYCAPTION))         If @error Then Return SetError(1, 4, "GUICreate() - failed")         Local $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($pStream) ;create bitmap from a stream (here from the $sFormat in memory)         Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWndPreview) ;create a graphics object from a window handle         HotKeySet("{ESC}") ;Press Esc to close the preview window         GUISetState(@SW_SHOW)         Do             _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmapFromStream, 0, 0) ;display streamed image         Until GUIGetMsg() = $GUI_EVENT_CLOSE         HotKeySet("{ESC}", $sHotKeyEscFunction) ;Restore previous Esc functionality         _GDIPlus_GraphicsDispose($hGraphics)         _GDIPlus_BitmapDispose($hBitmapFromStream)         GUIDelete($hWndPreview)     EndIf     Local $hMemory = _WinAPI_GetHGlobalFromStream($pStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx     If @error Then Return SetError(2, 7, "_WinAPI_GetHGlobalFromStream() - failed")     Local $iMemSize = _MemGlobalSize($hMemory)     If Not $iMemSize Then Return SetError(2, 8, "_MemGlobalSize() - failed")     Local $tMemory = DllStructCreate("byte[" & $iMemSize & "]", _MemGlobalLock($hMemory))     Local $bData = DllStructGetData($tMemory, 1)     _WinAPI_ReleaseStream($pStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx     _MemGlobalFree($hMemory)     _GDIPlus_Shutdown() ; Shut down GDI+ library     ; OCR converting of the image to text     Local $TesseractExePath = @ProgramFilesDir & "\Tesseract-OCR\tesseract.exe" ;C:\Program Files (x86)\Tesseract-OCR\tesseract.exe     If Not FileExists($TesseractExePath) Then         $TesseractExePath = StringReplace($TesseractExePath, " (x86)", "") ;C:\Program Files\Tesseract-OCR\tesseract.exe         If Not FileExists($TesseractExePath) Then Return SetError(3, 0, "The file 'tesseract.exe' not found")     EndIf     Local $iPID = Run('"' & $TesseractExePath & '" stdin stdout -l ' & $lang & ' --psm 6"', @ScriptDir, @SW_HIDE, BitOR($STDIN_CHILD, $STDERR_CHILD, $STDOUT_CHILD))     StdinWrite($iPID, $bData)     StdinWrite($iPID) ; Calling StdinWrite without a second parameter closes the stream.     ProcessWaitClose($iPID) ; Wait until the process has closed using the PID returned by Run.     Local $sOutput = ''     If @error Then             Do                 $sOutput &= StderrRead($iPID) ; Read the Stderr stream of the PID returned by Run             Until @error             StdioClose($iPID)             Return SetError(3, 1, $sOutput)     EndIf     Do         $sOutput &= StdoutRead($iPID) ; Read the Stdout stream of the PID returned by Run     Until @error     StdioClose($iPID)          Return $sOutput EndFunc #EndRegion --- Functions  ---
    1 point
  4. I still suspect the script is running as 32bit, which remaps the software key to wow6432node. If this is the case, you'll think that you're checking : HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5 but in reality you'll be checking: HKEY_LOCAL_MACHINE\Software\WOW6432Node\Native Instruments\Guitar Rig 5 Make this the first line in the script and see if it changes things. #AutoIt3Wrapper_UseX64=Y Also FYI you're now not handling the success condition of RegRead correctly - The following will not happen! "The Value... " & $sValueName & " ...does exist!" Success and fail conditions differ between functions, so check the helpfile so you know what to look for! Edit: Correction
    1 point
  5. Ok, so here is my solution to scroll both listbox in parallel, when they got the same number of items : #include <GUIConstantsEx.au3> #include <GuiListBox.au3> #include <ScrollBarConstants.au3> #include <WinAPIShellEx.au3> #include <WindowsConstants.au3> OnAutoItExitRegister('OnAutoItExit') Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Global $g_hListBox[2], $g_hDll[2], $g_pDll[2], $g_idSubClass[2] = [9999, 9998], $g_iTopIndexOld = -1 Example() Func Example() Local $iLeft[2] = [50, 300], $sFormat[2] = ["%02d", "A - %02d"], $sFunction[2] = ['_SubclassProc_0', '_SubclassProc_1'] GUICreate("Sync scrolling V2 (mouse wheel / scrollbar / keyboard)", 550, 400) For $i = 0 To 1 $g_hListBox[$i] = GUICtrlGetHandle(GUICtrlCreateList("", $iLeft[$i], 50, 200, 300)) _GUICtrlListBox_BeginUpdate($g_hListBox[$i]) For $iRow = 0 To 99 _GUICtrlListBox_AddString($g_hListBox[$i], StringFormat($sFormat[$i], $iRow)) Next _GUICtrlListBox_EndUpdate($g_hListBox[$i]) ; Create a listbox callback function (to catch scrollbar messages, as listbox scrollbars are child windows of listbox controls) $g_hDll[$i] = DllCallbackRegister($sFunction[$i], 'lresult', 'hwnd;uint;wparam;lparam;uint_ptr;dword_ptr') $g_pDll[$i] = DllCallbackGetPtr($g_hDll[$i]) ; Install the listbox subclass callback (to handle messages related to listbox scrollbars) _WinAPI_SetWindowSubclass($g_hListBox[$i], $g_pDll[$i], $g_idSubClass[$i], 0) Next GUISetState() ; main loop takes care of mouse wheel & keyboard (up, down, pgup, pgdn, home, end) Local $iTopIndex = 0 Do For $i = 0 To 1 $iTopIndex = _GUICtrlListBox_GetTopIndex($g_hListBox[$i]) _CompareIndex($iTopIndex, $i) Next Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example ;============================================== Func _CompareIndex($iTopIndex, $iListBox) If $iTopIndex <> $g_iTopIndexOld Then _GUICtrlListBox_SetTopIndex($g_hListBox[Not $iListBox], $iTopIndex) ; [Not 0] => [1] , [Not 1] => [0] $g_iTopIndexOld = $iTopIndex EndIf EndFunc ;==>_CompareIndex ;============================================== Func _SubclassProc_0($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) #forceref $iID, $pData Switch $iMsg Case $WM_VSCROLL Local $iScrollRequest = BitAND($wParam, 0xFFFF) ; LoWord Local $iScrollPos = BitShift($wParam, 16) ; HiWord Local $iTopIndex = ($iScrollRequest = $SB_THUMBTRACK Or $iScrollRequest = $SB_THUMBPOSITION) _ ? $iScrollPos _ : _GUICtrlListBox_GetTopIndex($g_hListBox[0]) _CompareIndex($iTopIndex, 0) EndSwitch ; Call next function in subclass chain Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_SubclassProc_0 ;============================================== Func _SubclassProc_1($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) #forceref $iID, $pData Switch $iMsg Case $WM_VSCROLL Local $iScrollRequest = BitAND($wParam, 0xFFFF) ; LoWord Local $iScrollPos = BitShift($wParam, 16) ; HiWord Local $iTopIndex = ($iScrollRequest = $SB_THUMBTRACK Or $iScrollRequest = $SB_THUMBPOSITION) _ ? $iScrollPos _ : _GUICtrlListBox_GetTopIndex($g_hListBox[1]) _CompareIndex($iTopIndex, 1) EndSwitch ; Call next function in subclass chain Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_SubclassProc_1 ;============================================== Func OnAutoItExit() For $i = 1 To 0 Step - 1 ; Remove the listbox subclass callback _WinAPI_RemoveWindowSubclass($g_hListBox[$i], $g_pDll[$i], $g_idSubClass[$i]) ; Frees a previously created handle created with DllCallbackRegister DllCallbackFree($g_hDll[$i]) Next EndFunc ;==>OnAutoItExit In case someone is interested, I scripted 2 others : 1) Synchronize selections too (when both listbox got the same number of items) 2) Take care of listboxes that don't have the same number of items.
    1 point
  6. 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. #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
    1 point
×
×
  • Create New...