joncl Posted October 2, 2007 Share Posted October 2, 2007 Is there any way to get the screen coordinates of a control? It looks like ControlGetPos can only return the coords relative to the containing client area of the window. The reason I ask is I need to grab the color of a pixel within a control. PixelGetColor can take coords relative to a window, but only if it's active, which I can't guarantee. So I need to give PixelGetColor the screen coords of the control instead. I've been looking around for a while, but didn't find anything. I hope someone can help! Link to comment Share on other sites More sharing options...
Fossil Rock Posted October 2, 2007 Share Posted October 2, 2007 Try WinGetPos() + ControlGetPos(). Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
joncl Posted October 2, 2007 Author Share Posted October 2, 2007 (edited) Wow, thank you for the instant reply! I was thinking along those lines. The problem is really the height of the titlebar can vary with different themes, which would throw off the calculation. But I just found the WinGetClientSize function which I think is the key I need... I played around and came up with this which works! What's nice is the window doesn't need to be active and can even be behind another window... $winPos = WinGetPos( $aWindowHandle ) $clientSize = WinGetClientSize( $aWindowHandle ) $winWidth = $winPos[2] $winHeight = $winPos[3] $clientWidth = $clientSize[0] $clientHeight = $clientSize[1] $winBorder = ( $winWidth - $clientWidth ) / 2 ;~ assume the border is even along the sides and bottom! $titleBarHeight = $winHeight - $clientHeight - $winBorder $controlPos = ControlGetPos( $aWindowHandle , "", "[CLASS:List; INSTANCE:2]" ) $controlPosAbsX = $winPos[0] + $winBorder + $controlPos[0] $controlPosAbsY = $winPos[1] + $titleBarHeight + $controlPos[1] MsgBox( 0, "", "color: " & Hex( PixelGetColor( $controlPosAbsX + 8, $controlPosAbsY + 8 ), 6 ) ) MouseMove( $controlPosAbsX + 4, $controlPosAbsY + 8 ) Edited October 2, 2007 by joncl Link to comment Share on other sites More sharing options...
smashly Posted October 2, 2007 Share Posted October 2, 2007 (edited) Hi, I use ClientToScreen api call save calculating, example...expandcollapse popup#include <GUIConstants.au3> Global $state, $CGP, $CTS, $Gui, $listview, $button $Gui = GUICreate("listview resize", 220, 200) $listview = GUICtrlCreateListView ("col1 |col2|col3 ", 10, 10, 200, 150) $button = GUICtrlCreateButton ("Resize",75,170,70,20) GUICtrlCreateListViewItem("item2|col22|col23",$listview) GUISetState() While 1 $msg = GUIGetMsg () Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $button $CGP = ControlGetPos($Gui, "", $listview) $CTS = ClientToScreen($Gui, $CGP[0], $CGP[1]) MsgBox(0, "Before Resize", "Ctrl Pos X: " & $CGP[0] & @LF & "Ctrl Pos Y: " & $CGP[1] & @LF & _ "Screen Pos X: " & $CTS[0] & @LF & "Screen Pos Y: " & $CTS[1]) If Not $state Then $state = 1 ControlMove($Gui, "", $listview, 40, 40, 140, 100) Else $state = 0 ControlMove($Gui, "", $listview, 10, 10, 200, 150) EndIf $CGP = ControlGetPos($Gui, "", $listview) $CTS = ClientToScreen($Gui, $CGP[0], $CGP[1]) MsgBox(0, "After Resize", "Ctrl Pos X: " & $CGP[0] & @LF & "Ctrl Pos Y: " & $CGP[1] & @LF & _ "Screen Pos X: " & $CTS[0] & @LF & "Screen Pos Y: " & $CTS[1]) EndSelect WEnd Func ClientToScreen($hWnd, $cX, $cY) Local $Point, $aRes[2] $Point = DllStructCreate("int;int") DllStructSetData($Point, 1, $cX) DllStructSetData($Point, 2, $cY) DllCall("User32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($Point)) $aRes[0] = DllStructGetData($Point, 1) $aRes[1] = DllStructGetData($Point, 2) Return $aRes EndFunc But whatever works for you is best Edited October 8, 2007 by smashly Link to comment Share on other sites More sharing options...
joncl Posted October 5, 2007 Author Share Posted October 5, 2007 smashly, thanks for the code! Indeed, your code gives exactly the same results. I've no experience calling user32.dll, but it seems like the better way to do it. It helps a lot, thanks! Link to comment Share on other sites More sharing options...
smashly Posted October 5, 2007 Share Posted October 5, 2007 Your Welcome........I've no experience calling user32.dll, ......Lol.. that makes 2 of us, I only modded a bit of code from A3Lib windows api udf Link to comment Share on other sites More sharing options...
joncl Posted October 5, 2007 Author Share Posted October 5, 2007 I'm looking all over for the "A3lib window api udf". Is this part of the "User Definied Fuctions" section in AutoIt Help? Does the api get installed with AutoIt? Well, at least I know what/where user32.dll is. 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