WinGetClientPos and Window Spy Topic is solved

Discuss the future of the AutoHotkey language
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

WinGetClientPos and Window Spy

10 Feb 2018, 06:25

- AHK v2's WinGetClientPos function, and Window Spy (WindowSpy.ahk), are showing different values for the active window's client position.
- The WinGetClientPos function shows what I believe to be the correct X/Y values.
- Window Spy shows what I believe to be the correct width/height values.
- I provide a custom function below which I believe shows all of the correct values.
- Note: Window Spy does not show any X/Y values for the active window's client position, there is a gap where it could be added, and I believe it would only take about 2 changes to the code, to add it in.

Code: Select all

q:: ;test WinGetClientPos
hWnd := WinGetID("A")

;note: 'client pos'
WinGetClientPos(vWinX, vWinY, vWinW, vWinH, "A")
vCoords1 := Format("x{} y{} w{} h{}", vWinX, vWinY, vWinW, vWinH)

;note: 'pos client'
JEE_WinGetPosClient(hWnd, vWinX, vWinY, vWinW, vWinH)
vCoords2 := Format("x{} y{} w{} h{}", vWinX, vWinY, vWinW, vWinH)

vWinX := vWinY := "__"
GetClientSize(hWnd, vWinW, vWinH) ;from WindowSpy.ahk
vCoords3 := Format("x{} y{} w{} h{}", vWinX, vWinY, vWinW, vWinH)
MsgBox(vCoords1 " AHK v2" "`r`n" vCoords2 " custom" "`r`n" vCoords3 " Window Spy")
return

JEE_WinGetPosClient(hWnd, ByRef vWinX, ByRef vWinY, ByRef vWinW, ByRef vWinH)
{
	VarSetCapacity(RECT, 16, 0)
	DllCall("user32\GetClientRect", Ptr,hWnd, Ptr,&RECT)
	DllCall("user32\ClientToScreen", Ptr,hWnd, Ptr,&RECT)
	vWinX := NumGet(&RECT, 0, "Int"), vWinY := NumGet(&RECT, 4, "Int")
	vWinW := NumGet(&RECT, 8, "Int"), vWinH := NumGet(&RECT, 12, "Int")
}

GetClientSize(hWnd, ByRef w := "", ByRef h := "")
{
	VarSetCapacity(rect, 16)
	DllCall("GetClientRect", "ptr", hWnd, "ptr", &rect)
	w := NumGet(rect, 8, "int")
	h := NumGet(rect, 12, "int")
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: WinGetClientPos and Window Spy

10 Feb 2018, 13:41

As far as I can tell, WinGetClientPos isn't documented. It gives you the coordinates of the upper left corner of the client area, and the coordinates of the lower right corner (in screen coords). Example,

Code: Select all

q:: ;)
	winGetClientPos(x1,y1,x2,y2,"A")
	msgbox "w: " x2-x1 "`th: " y2-y1
return
Cheers.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinGetClientPos and Window Spy

10 Feb 2018, 18:07

Great, thanks so much Helgef. I trusted that there might be a reasonable explanation, but I just wasn't expecting XYRB (aka TLRB) instead of XYWH. A fix for my code above:

Code: Select all

;note: 'client pos'
WinGetClientPos(vWinX, vWinY, vWinR, vWinB, "A")
vWinW := vWinR-vWinX, vWinH := vWinB-vWinY
vCoords1 := Format("x{} y{} w{} h{}", vWinX, vWinY, vWinW, vWinH)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: WinGetClientPos and Window Spy  Topic is solved

10 Feb 2018, 21:39

Helgef wrote:As far as I can tell, WinGetClientPos isn't documented.
Oops.
It gives you [...] the coordinates of the lower right corner (in screen coords).
Double oops. It's not supposed to do that.

Edit: Fixed in v2.0-a089.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 59 guests