Page 1 of 1

WinGetClientPos and Window Spy

Posted: 10 Feb 2018, 06:25
by jeeswg
- 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")
}

Re: WinGetClientPos and Window Spy

Posted: 10 Feb 2018, 13:41
by Helgef
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.

Re: WinGetClientPos and Window Spy

Posted: 10 Feb 2018, 18:07
by jeeswg
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)

Re: WinGetClientPos and Window Spy  Topic is solved

Posted: 10 Feb 2018, 21:39
by lexikos
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.