Getting Window Client position

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
joefiesta
Posts: 498
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Getting Window Client position

13 Nov 2023, 14:08

If found the function WinGetClientPos() here: https://www.autohotkey.com/board/topic/98679-function-wingetclientpos/

I reduced it to the following, where I simply plug in (for simplicity in testing) the target window's HWND.

Client := WinGetClientPos(5310346)
msgbox % "x" Client.X " y" Client.Y " w" Client.W " h" Client.H
return

WinGetClientPos( Hwnd ) {
VarSetCapacity( size, 16, 0 )
DllCall( "GetClientRect", UInt, Hwnd, Ptr, &size )
DllCall( "ClientToScreen", UInt, Hwnd, Ptr, &size )
x := NumGet(size, 0, "Int")
y := NumGet(size, 4, "Int")
w := NumGet( size, 8, "Int" )
h := NumGet( size, 12, "Int" )
return { X: x, Y: y, W: w, H: h }
}


Apparently, if it ever worked, it was for 32-bit AHK.
I run Win10 64 bit.
Can someone tell me how to make this work?
iPhilip
Posts: 827
Joined: 02 Oct 2013, 12:21

Re: Getting Window Client position

13 Nov 2023, 14:11

Why not use the built-in WinGetClientPos?
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
gregster
Posts: 9085
Joined: 30 Sep 2013, 06:48

Re: Getting Window Client position

13 Nov 2023, 14:15

I assume this is again a v1 question posted in the wrong forum?
Btw, for code boxes I would recommend code-tags instead of c-tags, which are meant for inline code.
iPhilip
Posts: 827
Joined: 02 Oct 2013, 12:21

Re: Getting Window Client position

13 Nov 2023, 14:19

If it's a v1 question, the solution is simply to replace UInt with Ptr in the DllCall's.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
joefiesta
Posts: 498
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Getting Window Client position

13 Nov 2023, 14:22

sorry, I was just about to edit. this after I noticed that, yes, it is in the WRONG forum. It is for V1. And, V1 has no WinGetClientPos.
joefiesta
Posts: 498
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Getting Window Client position

13 Nov 2023, 14:25

@iPhillip: I tried as you suggested. It didn't help. New code:

Code: Select all

Client := WinGetClientPos(5310346)
msgbox  % "x" Client.X " y" Client.Y " w" Client.W " h" Client.H
return

WinGetClientPos( Hwnd ) {
   VarSetCapacity( size, 16, 0 )
   DllCall( "GetClientRect", Ptr, Hwnd, Ptr, &size )
   DllCall( "ClientToScreen", Ptr, Hwnd, Ptr, &size )
   x := NumGet(size, 0, "Int")
   y := NumGet(size, 4, "Int")
   w := NumGet( size, 8, "Int" )
   h := NumGet( size, 12, "Int" )
   return { X: x, Y: y, W: w, H: h }
}
@gregster How do I use Code tags? Are they one of the icons shown when using Full editor? edit: nevermind... i hovered over the icons and found which it is.
gregster
Posts: 9085
Joined: 30 Sep 2013, 06:48

Re: Getting Window Client position

13 Nov 2023, 14:30

Okay, I moved the topic to v1 help.

You can insert code tags by using the fifth button from the left in the full editor. It either says Code or </>, depending on the used forum theme.

ctags.png
ctags.png (14.2 KiB) Viewed 626 times
iPhilip
Posts: 827
Joined: 02 Oct 2013, 12:21

Re: Getting Window Client position

13 Nov 2023, 14:34

@joefiesta, This works for me:

Code: Select all

Client := WinGetClientPos(WinExist("A"))
msgbox  % "x" Client.X " y" Client.Y " w" Client.W " h" Client.H  ; x0 y43 w1920 h997
return

WinGetClientPos( Hwnd ) {
   VarSetCapacity( size, 16, 0 )
   DllCall( "GetClientRect", Ptr, Hwnd, Ptr, &size )
   DllCall( "ClientToScreen", Ptr, Hwnd, Ptr, &size )
   x := NumGet(size, 0, "Int")
   y := NumGet(size, 4, "Int")
   w := NumGet( size, 8, "Int" )
   h := NumGet( size, 12, "Int" )
   return { X: x, Y: y, W: w, H: h }
}
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
just me
Posts: 9528
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Getting Window Client position

14 Nov 2023, 08:41

Code: Select all

Client := WinGetClientPos(5310346)
If the number is a window handle (HWND): Window handles are arbitrary. Each time a window is created it gets a new HWND which is only valid until the window is destroyed. Are you sure this HWND belongs to your target window?
joefiesta
Posts: 498
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Getting Window Client position

14 Nov 2023, 10:28

This question is resolved. Thanks all.

@iPhillip : thanks for the experimenting. I don't know what I did wrong, but you were absolutely correct. It's work fine for me now.

@ Jkust me : I realize what you said about hwnd. If you notice, I mentioned the example was just overly simplified for testing, including not getting any window but rather one that, for me, always exists.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Gorgrak, Leonardo_Portela, Sean24 and 121 guests