XTensionX Posted June 30, 2011 Posted June 30, 2011 Hi, im wondering if there is a way to get the colour of a label in my GUI. I've looked around but there dont seem to be any. Thanks
PsaltyDS Posted June 30, 2011 Posted June 30, 2011 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
guinness Posted June 30, 2011 Posted June 30, 2011 Thanks PsaltyDS UDF List: Reveal hidden contents _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
XTensionX Posted June 30, 2011 Author Posted June 30, 2011 Thanks guys But I wanted to get the colour of the text and not the background. How can I change the function to make it get the text colour in the Label?
guinness Posted June 30, 2011 Posted June 30, 2011 (edited) Did you set the colour of the text? And you didn't mention this in the OP! Edited June 30, 2011 by guinness UDF List: Reveal hidden contents _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
XTensionX Posted June 30, 2011 Author Posted June 30, 2011 On 6/30/2011 at 8:56 PM, 'guinness said: Did you set the colour of the text? And you didn't mention this in the OP! My bad =/ yeah I did, I have used the example of GUICtrGetBkColor() from your example script to test it out: #include <WinAPIEx.au3> ; Reguired for _WinAPI_GetPixel() _Main() Func _Main() Local $aColor_Array[6] = [5, 0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random Color Array. Local $hGUI, $iColor, $iLabel $hGUI = GUICreate("GUICtrlGetBkColor() Example", 500, 350) $iLabel = GUICtrlCreateLabel("wt", 0, 0, 500, 350) GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) $iColor = GUICtrlGetBkColor($iLabel) MsgBox(0, "The Hex value is...", _ConvertToHexFormat($iColor)) Exit EndFunc ;==>_Main Func _ConvertToHexFormat($iColor) Return Hex($iColor, 6) EndFunc ;==>_ConvertToHexForma Func GUICtrlGetBkColor($iControlID) Local $bGetBkColor, $hDC, $hHandle $hHandle = GUICtrlGetHandle($iControlID) $hDC = _WinAPI_GetDC($hHandle) $bGetBkColor = _WinAPI_GetPixel($hDC, 0, 0) _WinAPI_ReleaseDC($hHandle, $hDC) Return $bGetBkColor EndFunc ;==>GUICtrlGetBkColor
guinness Posted June 30, 2011 Posted June 30, 2011 I could be wrong, but I don't think what you're asking is possible. UDF List: Reveal hidden contents _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
PsaltyDS Posted July 1, 2011 Posted July 1, 2011 (edited) Hmm... seems like this should have worked, but it doesn't: #include <WinAPIEx.au3> _Main() Func _Main() Local $aColor_Array[6] = [5, 0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random Color Array. Local $hGUI, $iColor, $aLabel[6] = [5] $hGUI = GUICreate("GUICtrlGetBkColor() Example", 500, 350) For $n = 1 To 5 $aLabel[$n] = GUICtrlCreateLabel("Label " & $n, 10, 10 + ($n * 30), 480, 20) GUICtrlSetColor($aLabel[$n], $aColor_Array[$n]) Next GUISetState(@SW_SHOW) For $n = 1 To 5 $hHandle = GUICtrlGetHandle($aLabel[$n]) $hDC = _WinAPI_GetDC($hHandle) $iColor = _WinAPI_GetTextColor($hDC) $iErrSav = @error ConsoleWrite("$aColor_Array[" & $n & "] = 0x" & Hex($aColor_Array[$n]) & "; $aLabel[" & $n & "] = " & $aLabel[$n] & _ "; $hHandle = " & $hHandle & "; $hDC = " & $hDC & "; $iColor = 0x" & Hex($iColor) & "; @error = " & $iErrSav & @LF) _WinAPI_ReleaseDC($hHandle, $hDC) Next Do Until GUIGetMsg() = -3 EndFunc ;==>_Main Edited July 1, 2011 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
AdmiralAlkex Posted July 1, 2011 Posted July 1, 2011 (edited) You could "cheat". As you change the color, save it to a array and read later. Edited July 1, 2011 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
monoscout999 Posted July 1, 2011 Posted July 1, 2011 (edited) This also should work, but nope... #include <WinAPIEx.au3> #include <WindowsConstants.au3> Global $hGUI, $iColor, $aLabel[6] = [5] _Main() Func _Main() Local $aColor_Array[6] = [5, 0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random Color Array. $hGUI = GUICreate("GUICtrlGetBkColor() Example", 500, 350) GUIRegisterMsg($WM_CTLCOLORSTATIC, "WM_CTLCOLORSTATIC") For $n = 1 To 5 $aLabel[$n] = GUICtrlCreateLabel("Label " & $n, 10, 10 + ($n * 30), 480, 20) GUICtrlSetColor($aLabel[$n], $aColor_Array[$n]) Next GUICtrlCreateButton("", 150, 200, 100, 60) GUISetState(@SW_SHOW) Do Until GUIGetMsg() = -3 EndFunc ;==>_Main Func WM_CTLCOLORSTATIC($hWnd, $Msg, $wParam, $lParam) _WinAPI_SetTextColor($wParam, 0xff0000) ; All the labels must have red text.. _WinAPI_SetBkColor($wParam, 0x000000) ; All the labels must have black background.. ; _winapi_getbkcolor($wParam) _WinAPI_SetBkMode($wParam, $OPAQUE) ; All the labels must not have transparent Bk.. Return "GUI_RUNDEFMSG" EndFunc ;==>WM_CTLCOLORSTATIC Edited July 1, 2011 by monoscout999
XTensionX Posted July 1, 2011 Author Posted July 1, 2011 Thanks for the replies guys Guess this isnt possible :/
Moderators Melba23 Posted July 2, 2011 Moderators Posted July 2, 2011 XTensionX, Quote Guess this isnt possibleGuessed wrong! expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $hLabel = GUICtrlCreateLabel("Test", 10, 10, 100, 20) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState() $iBackColour = GUICtrlGetBkColorEx($hLabel) ConsoleWrite("BackColor: 0x" & Hex($iBackColour, 6) & @CRLF) $iTextColour = _GUICtrlGetTextColor($hGUI, $hLabel, $iBackColour) If @error Then ConsoleWrite("No text found" & @CRLF) Else ConsoleWrite("TextColor: 0x" & Hex($iTextColour, 6) & @CRLF) EndIf While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _GUICtrlGetTextColor($hWnd, $hControl, $iBkCol) Local $tPoint = DllStructCreate("int X;int Y") ; Get position of control Local $aPos = ControlGetPos($hGUI, "", $hControl) ; Convert to screen coords DllStructSetData($tPoint, "X", $aPos[0]) DllStructSetData($tPoint, "Y", $aPos[1]) _WinAPI_ClientToScreen($hGUI, $tPoint) $aPos[0] = DllStructGetData($tPoint, "X") + 1 ; Needs the added 1 to hit the first coloured pixel $aPos[1] = DllStructGetData($tPoint, "Y") + 1 ; I have no idea why ; Sweep through control to find another colour For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 2 ; Again the need to adjust the coords returned by ControlGetPos For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 2 ; And here too If PixelGetColor($iX, $iY) <> $iBkCol Then ; Assume that it is text colour Return PixelGetColor($iX, $iY) EndIf Next Next ; Text colour not found, so return error Return SetError(1, 0, 0) EndFunc Func GUICtrlGetBkColorEx($iControlID) Local $aResult, $bGetBkColor, $hDC, $hHandle $hHandle = GUICtrlGetHandle($iControlID) $aResult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hHandle) If @error Then Return SetError(@error, @extended, 0) EndIf $hDC = $aResult[0] $aResult = DllCall("gdi32.dll", "dword", "GetPixel", "hwnd", $hDC, "int", 0, "int", 0) If @error Or ($aResult[0] = 0xFFFFFFFF) Then Return SetError(@error, @extended, 0) EndIf $bGetBkColor = $aResult[0] $aResult = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hHandle, "handle", $hDC) If @error Then Return SetError(@error, @extended, 0) EndIf Return BitOR(BitAND($bGetBkColor, 0x00FF00), BitShift(BitAND($bGetBkColor, 0x0000FF), -16), BitShift(BitAND($bGetBkColor, 0xFF0000), 16)) EndFunc ;==>GUICtrlGetBkColorEx Not pretty but it works. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
taietel Posted July 2, 2011 Posted July 2, 2011 (edited) Sweet! This should go straight to the example scripts and your signature. Thanks Melba! [EDIT]Windows 7, 32 bit, classic theme. Edited July 2, 2011 by taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Reveal hidden contents Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
Info Posted July 2, 2011 Posted July 2, 2011 (edited) Not working for me Melba. The text color output is wrong and changes every time I run the script.Edit: Seems like the aero fading effect of Windows 7 caused the problem.Passing WinWait($hGUI) after GUISetState() fixes it.Great work Melba! Edited July 3, 2011 by Info
PsaltyDS Posted July 2, 2011 Posted July 2, 2011 (edited) On 7/2/2011 at 8:13 AM, 'Melba23 said: Not pretty but it works. Hmm... not for me. You are setting background to 0xFFFF00 (yellow), and text to 0xFF0000. But this is what I get: >Running:(3.3.7.10):C:\Program Files\AutoIt3\Beta\autoit3.exe "C:\Temp\Test1.au3" BackColor: 0xFFFF00 TextColor: 0xE5ECF3 Moreover, I get a different color every time, i.e. 0xB0B5F6, 0xF4F0F9, etc. Same problem in either Prod or Beta. Win7Pro x32. Edit: Added some debug to it, and now I get the same wrong answer every time. Weird. Debug version: expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $hLabel = GUICtrlCreateLabel("Test", 10, 10, 100, 20) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState() $iBackColour = GUICtrlGetBkColorEx($hLabel) ConsoleWrite("BackColor: 0x" & Hex($iBackColour, 6) & @CRLF) $iTextColour = _GUICtrlGetTextColor($hGUI, $hLabel, $iBackColour) If @error Then ConsoleWrite("No text found" & @CRLF) Else ConsoleWrite("TextColor: 0x" & Hex($iTextColour, 6) & @CRLF) EndIf While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _GUICtrlGetTextColor($hWnd, $hControl, $iBkCol) Local $tPoint = DllStructCreate("int X;int Y") ; Get position of control Local $aPos = ControlGetPos($hGUI, "", $hControl) ; Convert to screen coords DllStructSetData($tPoint, "X", $aPos[0]) DllStructSetData($tPoint, "Y", $aPos[1]) _WinAPI_ClientToScreen($hGUI, $tPoint) $aPos[0] = DllStructGetData($tPoint, "X") + 1 ; Needs the added 1 to hit the first coloured pixel $aPos[1] = DllStructGetData($tPoint, "Y") + 1 ; I have no idea why ConsoleWrite("Debug: X = " & $aPos[0] & "; Y = " & $aPos[1] & "; W = " & $aPos[2] & "; H = " & $aPos[3] & @LF) ; Sweep through control to find another colour For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 2 ; Again the need to adjust the coords returned by ControlGetPos For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 2 ; And here too $iFindColor = PixelGetColor($iX, $iY) ConsoleWrite("Debug: $iX = " & $iX & "; $iY = " & $iY & "; $iFindColor = 0x" & Hex($iFindColor, 6) & @LF) If $iFindColor <> $iBkCol Then ; Assume that it is text colour MouseMove($iX, $iY) ; Point to where it was found Return $iFindColor EndIf Next Next ; Text colour not found, so return error Return SetError(1, 0, 0) EndFunc ;==>_GUICtrlGetTextColor Func GUICtrlGetBkColorEx($iControlID) Local $aResult, $bGetBkColor, $hDC, $hHandle $hHandle = GUICtrlGetHandle($iControlID) $aResult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hHandle) If @error Then Return SetError(@error, @extended, 0) EndIf $hDC = $aResult[0] $aResult = DllCall("gdi32.dll", "dword", "GetPixel", "hwnd", $hDC, "int", 0, "int", 0) If @error Or ($aResult[0] = 0xFFFFFFFF) Then Return SetError(@error, @extended, 0) EndIf $bGetBkColor = $aResult[0] $aResult = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hHandle, "handle", $hDC) If @error Then Return SetError(@error, @extended, 0) EndIf Return BitOR(BitAND($bGetBkColor, 0x00FF00), BitShift(BitAND($bGetBkColor, 0x0000FF), -16), BitShift(BitAND($bGetBkColor, 0xFF0000), 16)) EndFunc ;==>GUICtrlGetBkColorEx Result: >Running:(3.3.7.10):C:\Program Files\AutoIt3\Beta\autoit3.exe "C:\Temp\Test1.au3" BackColor: 0xFFFF00 Debug: X = 445; Y = 137; W = 100; H = 20 Debug: $iX = 445; $iY = 137; $iFindColor = 0xF0F4F9 TextColor: 0xF0F4F9 I don't get it. The mouse pointer goes to the right place, so it looks like PixelGetColor() is actually failing. Edited July 2, 2011 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
PsaltyDS Posted July 2, 2011 Posted July 2, 2011 (edited) Arrrgh! Just put a Sleep() after GuiSetState() and it works! The pixel checking was happening before the GUI was displayed. This could be variable based on Windows effects like fading in new windows. Sheesh! And could have saved myself all the trouble by reading Info's post earlier! Edited July 2, 2011 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
monoscout999 Posted July 2, 2011 Posted July 2, 2011 You did a good job melba23... but despite that you find a solution, i still have the bitter sensation that the _winapi_gettextcolor() function should be work, but it doesn´t, even with Static classes outside autoit.
guinness Posted July 2, 2011 Posted July 2, 2011 Well I never! UDF List: Reveal hidden contents _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
XTensionX Posted July 3, 2011 Author Posted July 3, 2011 On 7/2/2011 at 8:13 AM, 'Melba23 said: XTensionX, Guessed wrong! expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $hLabel = GUICtrlCreateLabel("Test", 10, 10, 100, 20) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState() $iBackColour = GUICtrlGetBkColorEx($hLabel) ConsoleWrite("BackColor: 0x" & Hex($iBackColour, 6) & @CRLF) $iTextColour = _GUICtrlGetTextColor($hGUI, $hLabel, $iBackColour) If @error Then ConsoleWrite("No text found" & @CRLF) Else ConsoleWrite("TextColor: 0x" & Hex($iTextColour, 6) & @CRLF) EndIf While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _GUICtrlGetTextColor($hWnd, $hControl, $iBkCol) Local $tPoint = DllStructCreate("int X;int Y") ; Get position of control Local $aPos = ControlGetPos($hGUI, "", $hControl) ; Convert to screen coords DllStructSetData($tPoint, "X", $aPos[0]) DllStructSetData($tPoint, "Y", $aPos[1]) _WinAPI_ClientToScreen($hGUI, $tPoint) $aPos[0] = DllStructGetData($tPoint, "X") + 1 ; Needs the added 1 to hit the first coloured pixel $aPos[1] = DllStructGetData($tPoint, "Y") + 1 ; I have no idea why ; Sweep through control to find another colour For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 2 ; Again the need to adjust the coords returned by ControlGetPos For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 2 ; And here too If PixelGetColor($iX, $iY) <> $iBkCol Then ; Assume that it is text colour Return PixelGetColor($iX, $iY) EndIf Next Next ; Text colour not found, so return error Return SetError(1, 0, 0) EndFunc Func GUICtrlGetBkColorEx($iControlID) Local $aResult, $bGetBkColor, $hDC, $hHandle $hHandle = GUICtrlGetHandle($iControlID) $aResult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hHandle) If @error Then Return SetError(@error, @extended, 0) EndIf $hDC = $aResult[0] $aResult = DllCall("gdi32.dll", "dword", "GetPixel", "hwnd", $hDC, "int", 0, "int", 0) If @error Or ($aResult[0] = 0xFFFFFFFF) Then Return SetError(@error, @extended, 0) EndIf $bGetBkColor = $aResult[0] $aResult = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hHandle, "handle", $hDC) If @error Then Return SetError(@error, @extended, 0) EndIf Return BitOR(BitAND($bGetBkColor, 0x00FF00), BitShift(BitAND($bGetBkColor, 0x0000FF), -16), BitShift(BitAND($bGetBkColor, 0xFF0000), 16)) EndFunc ;==>GUICtrlGetBkColorEx Not pretty but it works. M23 Thanks Thanks Melba23 ^^ This is working perfectly
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