Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Get the control from an X Y position


  • Please log in to reply
4 replies to this topic
shader
  • Members
  • 56 posts
  • Last active: Nov 16 2011 09:05 AM
  • Joined: 29 Oct 2004
It would be really great to get the controls name from an X Y position. Being able to do that, the slow WinGet with his loop wouldn't be necessary. Thanks.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I've put this on the to-do list. Thanks.

ControlXY
  • Guests
  • Last active:
  • Joined: --
Is this possible, I can't find a way to do this?

Thanks.

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
Unless you're doing a bazillion checks, there should be no noticeable performance hit from using something like this:

;
; ControlsAtPos() by infogulch
;
; Returns:
;  A linefeed-delimited list of control hwnds 
;  that intersect the given position in a window.
; 
; Params:
;  WinTitle: the parent window from which to find controls
;  fx, fy: the coordinates, relative to the parent, which the controls must overlap
; 
; library compatible if named ControlsAtPos.ahk 
; 

ControlsAtPos(WinTitle, fx, fy) {
	WinGet, list, ControlListHwnd, %WinTitle%
	loop, parse, list, `n
	{
		ControlGetPos, x, y, w, h, , ahk_id %A_LoopField%
		if (x <= fx && fx <= x+w) && (y <= fy && fy <= y+h)
			ret .= "`n" A_LoopField  
		; controls can overlap, so a single position could theoretically
		;   have more than one control
	}
	return SubStr(ret, 2)
}


ControlXY
  • Guests
  • Last active:
  • Joined: --
Thank you :wink: