convert coordinates between Client/Screen/Window modes

Post your working scripts, libraries and tools
User avatar
jeeswg
Posts: 3542
Joined: 19 Dec 2016, 01:58
Location: UK

convert coordinates between Client/Screen/Window modes

17 Oct 2017, 17:51

I have produced 6 functions to convert an (X,Y) pair between different coordinate modes (Client / Screen / Window). Note for XYWH coordinates, X/Y changes but W/H remains the same.

Simpler:
JEE_ClientToScreen/JEE_ScreenToClient
JEE_ScreenToWindow/JEE_WindowToScreen

Slightly longer (client to screen to window, and window to screen to client):
JEE_ClientToWindow/JEE_WindowToClient

I have two scripts, one which recreates the generation of the A_CaretX and A_CaretY values, the other which test converting between coordinate modes.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



==================================================

[EDIT:] Here are two additional functions: JEE_WinGetPosClient and JEE_CtlGetPosClient.
[EDIT:] See lower down also for: JEE_CaretGetPos.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 31 Oct 2017, 05:35, edited 3 times in total.
Helgef
Posts: 2674
Joined: 17 Jul 2016, 01:02
Contact:

Re: convert coordinates between Client/Screen/Window modes

19 Oct 2017, 16:42

Hello jeeswg, thanks for sharing. :thumbup:

Slightly longer (client to screen to window, and window to screen to client):
JEE_ClientToWindow/JEE_WindowToClient

Slightly shorter,

Code: [Select all] [Download] GeSHi © Codebox Plus

JEE_ClientToWindow(...){
JEE_ClientToScreen(...)
JEE_ScreenToWindow(...)
}
JEE_WindowToClient(...){
JEE_WindowToScreen(...)
JEE_ScreenToClient(...)
}

:angel:

I have two scripts, one which recreates the generation of the A_CaretX and A_CaretY values

Dear :xmas: , I wish you had made it a (v2) function, GetCaretPos(outX, outY) where outX, outY adheres to A_CoordModeCaret.

Thanks for your efforts, cheers

Edit: Why not use wingetpos() instead of dllcall(GetWindowRect)?
User avatar
jeeswg
Posts: 3542
Joined: 19 Dec 2016, 01:58
Location: UK

Re: convert coordinates between Client/Screen/Window modes

19 Oct 2017, 16:56

Yes, a wise angel, I had realised that I could write the functions as two function calls. I always write functions as stand-alone or pretty much stand-alone where possible, for a quick copy-and-paste without/with few dependencies.

Haha if people start making Christmas requests for functions I won't have time for anything else this year. I did anticipate that you might request this, or wish to request this, based on that other thread, I'll give it a go. Btw would such a function be very useful to you?

I'm quite glad to have written these functions now, because they were confusing me for a long time.
Helgef
Posts: 2674
Joined: 17 Jul 2016, 01:02
Contact:

Re: convert coordinates between Client/Screen/Window modes

19 Oct 2017, 17:16

for a quick copy-and-paste without/with few dependencies.

That is reasonable.
Btw would such a function be very useful to you?

Not really at moment. However, you made most of the work already, so it slightly bothers me, that once I need it, there is work waiting ;) . But please, no hurry or presure in the matter, not for me at least.
I'm quite glad to have written these functions now

They are very useful functions, I have made at least some of them when needed, I don't think I collected them though. I will refer back here when needed :thumbup:
User avatar
jeeswg
Posts: 3542
Joined: 19 Dec 2016, 01:58
Location: UK

Re: convert coordinates between Client/Screen/Window modes

19 Oct 2017, 17:25

Oh you don't need them that much, next year then hehe.

Yes when you mentioned it before I envisaged a function that would get the caret position according to A_CoordModeCaret, but that could also return the raw numbers retrieved from GUITHREADINFO if specified by the optional mode parameter. Or indeed that you could manually specify Caret/Screen/Window, bypassing AHK's variable.

A-ha, here's the original thread:

CoordMode needs a pause to update - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=14&t=38467

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 06 Nov 2017, 13:50, edited 2 times in total.
Helgef
Posts: 2674
Joined: 17 Jul 2016, 01:02
Contact:

Re: convert coordinates between Client/Screen/Window modes

19 Oct 2017, 17:31

That was quick :lol:

Excellent idea. :thumbup:
User avatar
jeeswg
Posts: 3542
Joined: 19 Dec 2016, 01:58
Location: UK

Re: convert coordinates between Client/Screen/Window modes

13 Feb 2018, 15:46

A slight variant to allow specifying an hWnd. Based on comments by Drugwash here:
commands as functions (AHK v2 functions for AHK v1) - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=29689&p=200260#p200260

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

stealzy
Posts: 65
Joined: 01 Nov 2015, 13:43

Re: convert coordinates between Client/Screen/Window modes

13 Feb 2018, 16:51

Do not need convert, if you get all coordinate at once:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
Drugwash
Posts: 446
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: convert coordinates between Client/Screen/Window modes

13 Feb 2018, 18:49

Another vMode: f (forced, to focus window/control if not focused, otherwise coordinates will be null).
That'd be purrfect. :)
Now I can go to sleep.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], jcash, TAC109 and 22 guests