Yashied Posted April 4, 2009 Share Posted April 4, 2009 How can I get the current color of Input control not using PixelGetColor().Thanks. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 4, 2009 Moderators Share Posted April 4, 2009 I'm curious on why you need to get a default color.ControlGetHandle() or GUICtrlGetHandle()+http://msdn.microsoft.com/en-us/library/aa921543.aspx+http://msdn.microsoft.com/en-us/library/dd144852(VS.85).aspx Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Yashied Posted April 4, 2009 Author Share Posted April 4, 2009 ControlGetHandle() or GUICtrlGetHandle()+http://msdn.microsoft.com/en-us/library/aa921543.aspx+http://msdn.microsoft.com/en-us/library/dd144852(VS.85).aspxThank you, good solution. But this will only work for the Background color. I now use _WinAPI_GetSysColor($COLOR_WINDOWTEXT).I'm curious on why you need to get a default color.I need to change the text color of Input control and then return it back. I wanted to find the elegant solution. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 4, 2009 Moderators Share Posted April 4, 2009 (edited) Thank you, good solution. But this will only work for the Background color. I now use _WinAPI_GetSysColor($COLOR_WINDOWTEXT).I need to change the text color of Input control and then return it back. I wanted to find the elegant solution.You should have been much more specific. You didn't mention text anywhere .Edit:http://msdn.microsoft.com/en-us/library/dd144934(VS.85).aspxI believe that comes in BGR but easily remedied . Edited April 4, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Yashied Posted April 4, 2009 Author Share Posted April 4, 2009 You should have been much more specific. You didn't mention text anywhere .Sorry. Edit:http://msdn.microsoft.com/en-us/library/dd144934(VS.85).aspxI believe that comes in BGR but easily remedied .Many thanks to you! My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Yashied Posted April 4, 2009 Author Share Posted April 4, 2009 http://msdn.microsoft.com/en-us/library/dd144934(VS.85).aspx"GetTextColor" does not work, see example. #Include <WinAPI.au3> GUICreate('Test', 200, 200) $Input = GUICtrlCreateInput('Simple text', 20, 20, 160, 20) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFAFAFA) GUISetState() MsgBox(0, '', '0x' & Hex(_WinAPI_GetTextColor(GUICtrlGetHandle($Input)))) func _WinAPI_GetTextColor($hWnd) local $RGB, $hDC = _WinAPI_GetDC($hWnd) if $hDC = 0 then return SetError(1, 0, -1) endif $RGB = DllCall('gdi32.dll', 'int', 'GetTextColor', 'hwnd', $hDC) if (@error) or ($RGB[0] = 0xFFFFFFFF) then $RGB = -1 endif _WinAPI_ReleaseDC($hWnd, $hDC) if $RGB = -1 then return SetError(1, 0, -1) endif return SetError(0, 0, $RGB[0]) endfunc; _WinAPI_GetTextColor My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
ProgAndy Posted April 4, 2009 Share Posted April 4, 2009 This works: expandcollapse popup#Include <WinAPI.au3> #Include <WindowsConstants.au3> Global $WINDOW_TO_QUERY, $___RGB GUIRegisterMsg($WM_CTLCOLORSTATIC,"MY_CTLCOLOR") GUIRegisterMsg($WM_CTLCOLOREDIT,"MY_CTLCOLOR") GUIRegisterMsg($WM_CTLCOLORBTN,"MY_CTLCOLOR") GUICreate('Test', 200, 200) $Input = GUICtrlCreateInput('Simple text', 20, 20, 160, 20) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFAFAFA) GUISetState() MsgBox(0, '', '0x' & Hex(_WinAPI_GetTextColor(GUICtrlGetHandle($Input)))) func _WinAPI_GetTextColor($hWnd) ; Prog@ndy Global $___RGB = -1 $WINDOW_TO_QUERY = $hWnd _WinAPI_RedrawWindow($hWnd,0,0,$RDW_INVALIDATE+$RDW_UPDATENOW) Do Sleep(10) Until $___RGB <> -1 Return $___RGB endfunc; _WinAPI_GetTextColor Func MY_CTLCOLOR($hWnd,$uMsg,$wParam, $lParam) ; Prog@ndy If $lParam = $WINDOW_TO_QUERY Then Local $RGB = DllCall('gdi32.dll', 'int', 'GetTextColor', 'ptr', $wParam) If Not @error Then Global $___RGB = $RGB[0] Else Global $___RGB = -2 EndIf EndIf Return 'GUI_RUNDEFMSG' EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Yashied Posted April 4, 2009 Author Share Posted April 4, 2009 (edited) This works: expandcollapse popup#Include <WinAPI.au3> #Include <WindowsConstants.au3> Global $WINDOW_TO_QUERY, $___RGB GUIRegisterMsg($WM_CTLCOLORSTATIC,"MY_CTLCOLOR") GUIRegisterMsg($WM_CTLCOLOREDIT,"MY_CTLCOLOR") GUIRegisterMsg($WM_CTLCOLORBTN,"MY_CTLCOLOR") GUICreate('Test', 200, 200) $Input = GUICtrlCreateInput('Simple text', 20, 20, 160, 20) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFAFAFA) GUISetState() MsgBox(0, '', '0x' & Hex(_WinAPI_GetTextColor(GUICtrlGetHandle($Input)))) func _WinAPI_GetTextColor($hWnd) ; Prog@ndy Global $___RGB = -1 $WINDOW_TO_QUERY = $hWnd _WinAPI_RedrawWindow($hWnd,0,0,$RDW_INVALIDATE+$RDW_UPDATENOW) Do Sleep(10) Until $___RGB <> -1 Return $___RGB endfunc; _WinAPI_GetTextColor Func MY_CTLCOLOR($hWnd,$uMsg,$wParam, $lParam) ; Prog@ndy If $lParam = $WINDOW_TO_QUERY Then Local $RGB = DllCall('gdi32.dll', 'int', 'GetTextColor', 'ptr', $wParam) If Not @error Then Global $___RGB = $RGB[0] Else Global $___RGB = -2 EndIf EndIf Return 'GUI_RUNDEFMSG' EndFuncExelent example. Thanks. Edited April 6, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Malkey Posted April 4, 2009 Share Posted April 4, 2009 Added to ProgAndy's script, This script returns :- background colour if 2nd parameter is 0 or absent, using the gdi32.dll 'GetBkColor' function, or, text colour if 2nd parameter does not equal 0, using the gdi32.dll 'GetTextColor' function. And using _WinAPI_GetBkColor(), the background colour of a GUI is returned. expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> Global $WINDOW_TO_QUERY, $___RGBTC, $___RGBBGC GUIRegisterMsg($WM_CTLCOLORSTATIC, "MY_CTLCOLOR") GUIRegisterMsg($WM_CTLCOLOREDIT, "MY_CTLCOLOR") GUIRegisterMsg($WM_CTLCOLORBTN, "MY_CTLCOLOR") $hGui = GUICreate('Test', 200, 200) GUISetBkColor(0xABCDEF) $Input = GUICtrlCreateInput('Simple text', 20, 20, 160, 20) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFAFAFF) GUISetState() MsgBox(0, 'Colours in RGB format', 'Text colour input = : 0x' & Hex(_WinAPI_GetTextColor($Input, 1), 6) & @CRLF & _ 'BackGnd colour input = : 0x' & Hex(_WinAPI_GetTextColor($Input), 6) & @CRLF & _ 'BackGnd colour GUI = : 0x' & Hex(_WinAPI_GetBkColor($hGui), 6) & @CRLF) ; $BGC_TC = 0 for background colour, $BGC_TC <> 0 for text colour Func _WinAPI_GetTextColor($hWnd, $BGC_TC = 0) ; Prog@ndy Global $___RGBTC = -1, $___RGBBGC = -1 If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) $WINDOW_TO_QUERY = $hWnd _WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_INVALIDATE + $RDW_UPDATENOW) Do Sleep(10) Until $___RGBTC <> -1 And $___RGBBGC <> -1 If $BGC_TC = 0 Then Return $___RGBBGC Else Return $___RGBTC EndIf EndFunc ;==>_WinAPI_GetTextColor Func MY_CTLCOLOR($hWnd, $uMsg, $wParam, $lParam) ; Prog@ndy If $lParam = $WINDOW_TO_QUERY Then Local $RGB = DllCall('gdi32.dll', 'int', 'GetTextColor', 'ptr', $wParam) If Not @error Then Global $___RGBTC = "0x" & StringRegExpReplace(Hex($RGB[0], 6), "(.{2})(.{2})(.{2})", "\3\2\1") Else Global $___RGBTC = -2 EndIf Local $___RGBBGC = DllCall('gdi32.dll', 'int', 'GetBkColor', 'ptr', $wParam) If Not @error Then Global $___RGBBGC = "0x" & StringRegExpReplace(Hex($___RGBBGC[0], 6), "(.{2})(.{2})(.{2})", "\3\2\1") Else Global $___RGBBGC = -2 EndIf EndIf Return 'GUI_RUNDEFMSG' EndFunc ;==>MY_CTLCOLOR ; Get background colour of GUI window, NOT a control. Func _WinAPI_GetBkColor($hWnd) ; Not Prog@ndy Local $aResult, $hDC, $Res If Not IsHWnd($hWnd) Then $hWnd = ControlGetHandle("", "", $hWnd) $hDC = _WinAPI_GetDC($hWnd) $aResult = DllCall("GDI32.dll", "int", "GetBkColor", "hwnd", $hDC) ConsoleWrite("Hex($aResult[0], 6) = " & Hex($aResult[0], 6) & @CRLF) $Res = "0x" & StringRegExpReplace(Hex($aResult[0], 6), "(.{2})(.{2})(.{2})", "\3\2\1") _WinAPI_ReleaseDC($hWnd, $hDC) Return $Res EndFunc ;==>_WinAPI_GetBkColor 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