martin Posted December 1, 2008 Share Posted December 1, 2008 (edited) If I create a graphic with GUICtrlCreateGraphic and colour it with GUICtrlSetGraphic then it it invisible to PixelGetColor and to _ScreenCapture_Capture. How do I detect the colour under the mouse cursor when it is over the graphic? Edited December 1, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 1, 2008 Share Posted December 1, 2008 If I create a graphic with GUICtrlCreateGraphic and colour it with GUICtrlSetGraphic then it it invisible to PixelGetColor and to _ScreenCapture_Capture. How do I detect the colour under the mouse cursor when it is over the graphic? Can you post a reproducer? I don't see the issue using PixelGetColor() with a modified version of the GuiCtrlSetGraphic() example from the help file: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> Opt('MustDeclareVars', 1) Global $MAXGr = 6, $del, $child, $avMouse, $iPixel Global $a[$MAXGr + 1]; 0 and $MAXGr entries not used to allow GUICtrlDelete result Local $msg, $inc, $i, $del1 GUICreate("My Main", -1, -1, 100, 100) $del1 = GUICtrlCreateButton("Delete", 50, 200, 50) GUISetState() CreateChild() $i = 1 $inc = 1 Do $msg = GUIGetMsg() $avMouse = MouseGetPos() $iPixel = PixelGetColor($avMouse[0], $avMouse[1]) ToolTip("Pos X=" & $avMouse[0] & " Y=" & $avMouse[1] & " Color=0x" & Hex($iPixel, 6)) If $msg = $del1 Then $i = Del($inc) If $msg = $del Then GUICtrlDelete($a[$i]) $i = $i + $inc If $i < 0 Or $i > $MAXGr Then Exit EndIf Until $msg = $GUI_EVENT_CLOSE Func Del($iInc) GUIDelete($child) CreateChild() If $iInc = -1 Then Return 5 Return 1 EndFunc ;==>Del Func CreateChild() $child = GUICreate("My Draw") $del = GUICtrlCreateButton("Delete", 50, 165, 50) $a[1] = GUICtrlCreateGraphic(20, 50, 100, 100) GUICtrlSetBkColor(-1, 0xffffff) GUICtrlSetColor(-1, 0) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000, 0xff0000) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30, 270) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 58, 50, 40, -60, 90) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 100, 100, 50, 80) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xc0c0ff) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 350, 200, 50, 80) GUICtrlCreateLabel("label", 65, 100, 30) GUICtrlSetColor(-1, 0xff) $a[2] = GUICtrlCreateGraphic(220, 10, 100, 100) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30, 270) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 58, 50, 40, -60, 90) $a[3] = GUICtrlCreateGraphic(220, 110, 100, 100) GUICtrlSetBkColor(-1, 0xf08080) GUICtrlSetColor(-1, 0xff) GUICtrlSetGraphic(-1, $GUI_GR_HINT, 1) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff00) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 50, 50, 80, 80) $a[4] = GUICtrlCreateGraphic(20, 200, 80, 80) GUICtrlSetBkColor(-1, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_HINT, 1) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 10, 10) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 30, 40) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff00) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 70, 70) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 10, 50) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffff00) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 10, 10) $a[5] = GUICtrlCreateGraphic(150, 10, 50, 50) GUICtrlSetBkColor(-1, 0xa0ffa0) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 20, 20); start point ; it is better to draw line and after point ; to avoid to switch color at each drawing GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000ff) GUICtrlSetGraphic(-1, $GUI_GR_DOT, 30, 30) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 20, 40) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000) GUICtrlSetGraphic(-1, $GUI_GR_DOT, 25, 25) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 40, 40) GUICtrlSetGraphic(-1, $GUI_GR_DOT, 30, 40) $a[6] = GUICtrlCreateGraphic(110, 260, 230, 130) GUICtrlSetColor(-1, 0); to display a black border line GUICtrlSetBkColor(-1, 0xc0c0ff) GUICtrlSetGraphic(-1, $GUI_GR_HINT, 3); to display control lines and end points GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff); fill in blue GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 120, 20); start point GUICtrlSetGraphic(-1, $GUI_GR_BEZIER, 120, 100, 200, 20, 200, 100) GUICtrlSetGraphic(-1, $GUI_GR_BEZIER + $GUI_GR_CLOSE, 100, 40, 40, 100, 40, 20) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 60, 30); start point GUISetState() EndFunc ;==>CreateChild 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 Link to comment Share on other sites More sharing options...
martin Posted December 1, 2008 Author Share Posted December 1, 2008 Can you post a reproducer? I don't see the issue using PixelGetColor() with a modified version of the GuiCtrlSetGraphic() example from the help file: Yes that works fine, but the example below doesn't. I didn't realise it was significant but I have a layered window which I didn't mention. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <windowsconstants.au3> #include <screencapture.au3> ;Opt('MustDeclareVars', 1) Opt("MouseCoordMode", 1) Opt("PixelCoordMode", 1) Global $MAXGr = 6, $del Global $a[$MAXGr + 1]; 0 and $MAXGr entries not used to allow GUICtrlDelete result HotKeySet("{ESC}","quitall");escape route Example() Func Example() Local $msg, $inc, $i CreateChild() ;_ScreenCapture_Capture("blob.jpg");doesn't see the graphic $i = 1 $inc = 1 Do $avMouse = MouseGetPos() $iPixel = PixelGetColor($avMouse[0], $avMouse[1]) ToolTip("Pos X=" & $avMouse[0] & " Y=" & $avMouse[1] & " Color=0x" & Hex($iPixel, 6)) $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_PRIMARYDOWN $mp = MouseGetPos() ToolTip($mp[0] & ', ' & $mp[1], $mp[0], $mp[1]) ConsoleWrite(Hex(PixelGetColor(170, 170)) & @CRLF);$mp[0],$mp[1] If PixelGetColor($avMouse[0], $avMouse[1]) = 0 Then MsgBox(0, "YOU called?", "ok") EndIf EndSwitch Until 0 EndFunc ;==>Example Func CreateChild() Local $child $child = GUICreate("My Draw", 141, 141, 100, 100, $WS_POPUP, $WS_EX_LAYERED) $del = GUICtrlCreateButton("Delete", 50, 165, 50) $a[1] = GUICtrlCreateGraphic(0, 0, 141, 141) GUICtrlSetBkColor(-1, 0xababab) GUICtrlSetColor(-1, 0xababab) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xffff00) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 70, -45, 90) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 70, 45, 90) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xff0000) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 70, 135, 90) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x0000ff) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 70, 225, 90) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x000000) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 30, 0, 360) GUISetState() _API_SetLayeredWindowAttributes($child, 0xababab, 255) EndFunc ;==>CreateChild ;=============================================================================== ; ; Function Name: _API_SetLayeredWindowAttributes ; Description:: Sets Layered Window Attributes:) See MSDN for more informaion ; Parameter(s): ; $hwnd - Handle of GUI to work on ; $i_transcolor - Transparent color ; $Transparency - Set Transparancy of GUI ; $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color ; Requirement(s): Layered Windows ; Return Value(s): Success: 1 ; Error: 0 ; @error: 1 to 3 - Error from DllCall ; @error: 4 - Function did not succeed - use ; _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False) Local Const $AC_SRC_ALPHA = 1 Local Const $ULW_ALPHA = 2 Local Const $LWA_ALPHA = 0x2 Local Const $LWA_COLORKEY = 0x1 If Not $isColorRef Then $i_transcolor = Hex(String($i_transcolor), 6) $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2)) EndIf Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA) Select Case @error Return SetError(@error, 0, 0) Case $Ret[0] = 0 Return SetError(4, 0, 0) Case Else Return 1 EndSelect EndFunc ;==>_API_SetLayeredWindowAttributes Func quitall() Exit EndFunc Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
FireFox Posted December 1, 2008 Share Posted December 1, 2008 Hi, I dont know if that could help you, have you tried to hide cursor and get color ? _WinApi_ShowCursor(0);hide cursor _WinApi_ShowCursor(1);show cursor Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 1, 2008 Share Posted December 1, 2008 Yes that works fine, but the example below doesn't. I didn't realise it was significant but I have a layered window which I didn't mention.Yeah, I see the issue now, but you stumped me (don't expect any points for that, it's too easy to do). 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 Link to comment Share on other sites More sharing options...
martin Posted December 1, 2008 Author Share Posted December 1, 2008 Yeah, I see the issue now, but you stumped me (don't expect any points for that, it's too easy to do). Thanks for looking PsaltyDS. I thought there must be an easy answer but maybe there isn't.@ firefox, thanks for your suggestion but I wanted to place the cursor over a particular colur to control something so I need to see the cursor. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
monoceres Posted December 2, 2008 Share Posted December 2, 2008 martin, any specific reason you're working with the built in graphic functions instead of the GDI+ UDF? Oh and I couldn't reproduce on Vista. Probably because of dwm. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
martin Posted December 2, 2008 Author Share Posted December 2, 2008 martin, any specific reason you're working with the built in graphic functions instead of the GDI+ UDF? Oh and I couldn't reproduce on Vista. Probably because of dwm. Not really. It just seemed like a graphic would be a quick and easy way to draw the shape I wanted, but when I couldn't see the colour under the cursor I was just puzzled. I'll try with GDI+ maybe tonight. The object of creating the shape is not particulary important. Interesting to know that it's different on Vista, at least with the versions with dwm. That means that an application which looks the same on XP and Vista could give completely different screenshots. Maybe a way to test if you have dwm enabled. #include <GUIConstantsEx.au3> #include <windowsconstants.au3> $gui = GUICreate("My Draw", 10, 10, 0, 0, $WS_POPUP, $WS_EX_LAYERED) $gr = GUICtrlCreateGraphic(0, 0, 10, 10) GUICtrlSetBkColor(-1, 0xababab) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xf18ebc) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 10, 10) GUISetState() DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $gui, "long", 0xf18ebc, "byte", 255, "long", 3) $iPixel = PixelGetColor(5, 5) guidelete($gui) If $iPixel = 0xf18ebc Then MsgBox(262144, "Aero detected?", "You are probably using Vista with Areo") Else MsgBox(262144, "Problem!", "Outdated OS or setup detected.") EndIf (Not a serious suggestion btw in case someone thinks it is Search for DwmIsCompositionEnabled to detect dwm) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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