Get Window Title at Specific Coordinates

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Get Window Title at Specific Coordinates

22 Jun 2021, 11:42

emrekarahan0001 wrote: if title "Anasayfa / Twitter - Google Chrome"
But it must show "This text must be shown".
User avatar
emrekarahan0001
Posts: 25
Joined: 18 Jan 2021, 14:19

Re: Get Window Title at Specific Coordinates

22 Jun 2021, 11:48

teadrinker wrote:
22 Jun 2021, 11:42
emrekarahan0001 wrote: if title "Anasayfa / Twitter - Google Chrome"
But it must show "This text must be shown".
English = **Home** / Twitter - Google Chrome
Turkish = **Anasayfa** / Twitter - Google Chrome

Code: Select all

WinWait, **Home** / Twitter - Google Chrome
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Get Window Title at Specific Coordinates

22 Jun 2021, 11:51

emrekarahan0001 wrote: English = **Home** / Twitter - Google Chrome
Turkish = **Anasayfa** / Twitter - Google Chrome
This is a wrong result. If you launch my code, it must show "This text must be shown".
User avatar
emrekarahan0001
Posts: 25
Joined: 18 Jan 2021, 14:19

Re: Get Window Title at Specific Coordinates

22 Jun 2021, 11:56

teadrinker wrote:
22 Jun 2021, 11:51
emrekarahan0001 wrote: English = **Home** / Twitter - Google Chrome
Turkish = **Anasayfa** / Twitter - Google Chrome
This is a wrong result. If you launch my code, it must show "This text must be shown".
believe me brother, i understand you, but i can't explain to my problem.. whatever thank you :salute:
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Get Window Title at Specific Coordinates

22 Jun 2021, 12:07

emrekarahan0001 wrote: i can't explain to my problem
Can you say, what exactly you need to get? :)
User avatar
Avtem
Posts: 43
Joined: 01 Jun 2021, 02:20

Re: Get Window Title at Specific Coordinates

22 Jun 2021, 12:53

teadrinker wrote:
22 Jun 2021, 08:40
Try this:

Code: Select all

Gui, New, -Caption +Border
Gui, Margin, 0, 0
Gui, Font, s24
Gui, Add, Edit,, This text must be shown
Gui, Show, x497 y497
varSetCapacity(title, 200, 0)
DllCall("GetWindowText", "ptr", DllCall("WindowFromPoint", "Int", 500, "Int", 500)
      , "str", title, "int", 199)	
msgbox %title%
ExitApp
What the text the message box shows?
With this window it does not show "This text must be shown". i think the matter with the WindowFromPoint itself. It works in some 32 bit apps, and in some 64 bit apps, but more weirdly - with Telegram app it works on the right side of the app where messages are shown and on the left side where contacts are shown it does not. Interesting
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Get Window Title at Specific Coordinates

22 Jun 2021, 13:01

Avtem wrote: With this window it does not show "This text must be shown"
Now try launch the same code with 32 bit AHK.
User avatar
Avtem
Posts: 43
Joined: 01 Jun 2021, 02:20

Re: Get Window Title at Specific Coordinates

22 Jun 2021, 13:12

teadrinker wrote:
22 Jun 2021, 13:01
Now try launch the same code with 32 bit AHK.
Yep, under 32 bits i got the correct result. We are trying to get titles for Top windows, not Children - right?
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Get Window Title at Specific Coordinates

22 Jun 2021, 13:39

Avtem wrote: We are trying to get titles for Top windows, not Children - right?
Nope, the function WindowFromPoint gives you the window handle, within which a point is placed, independing on the type of the window, child or top level. If you need to get the handle of the parent window, you have to call winapi GetAncestor with GA_ROOT.
lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: Get Window Title at Specific Coordinates

23 Jun 2021, 04:57

emrekarahan0001 wrote:
22 Jun 2021, 10:37
DllCall("WindowFromPoint", "Int", 500, "Int", 500)
As I said, this will not work correctly on x64:
Passing the x and y coordinates as individual int parameters works for 32-bit because they are simply pushed onto the stack, right to left, 4 bytes at a time. This would not work with smaller types, because each parameter would be widened to 32-bit. It also would not work for x64 because each parameter (int) would be widened to 64-bit.
On x64, it is the same as this:

Code: Select all

DllCall("WindowFromPoint", "Int64", 500, "Int64", 500)
Since the function only expects one 64-bit parameter, it is the same as this:

Code: Select all

DllCall("WindowFromPoint", "Int64", 500)
To understand what it is returning, look only at the top row of pixels (Y coordinate 0).
mike34
Posts: 7
Joined: 10 Jul 2022, 07:07

Re: Get Window Title at Specific Coordinates

28 Jul 2022, 11:45

swagfag wrote:
10 May 2019, 13:34
@teadrinker
https://blogs.msdn.microsoft.com/oldnewthing/20101230-00/?p=11873/
last paragraph :lol:

Code: Select all

x := y := 500
CWP_ALL := 0x0000
CWP_SKIPINVISIBLE := 0x0001
CWP_SKIPDISABLED := 0x0002
CWP_SKIPTRANSPARENT := 0x0004
hwnd := DllCall("ChildWindowFromPointEx"
	, "Ptr", DllCall("GetDesktopWindow", "Ptr")
	, "UInt64", (x & 0xFFFFFFFF) | (y << 32)
	, "UInt", CWP_SKIPINVISIBLE | CWP_SKIPDISABLED | CWP_SKIPTRANSPARENT
	, "Ptr")
and x seems to break on negative coords if u dont mask it off

that aside, these functions behave very weirdly. its says it accepts a POINT BY VALUE, what?? but i tried

Code: Select all

VarSetCapacity(P, 8, 0)
NumPut(500, &P, 0, "Int")
NumPut(500, &P, 4, "Int")
; ... and passing it BY VALUE
, "Ptr", P
but it didnt work. it only checked (0, 0) on my 2 monitor (-1920, 1920) setup, which is the topleft corner of my rhs main monitor




this API doesn't work when the window is a child of another window?

Code: Select all

OnMessage(0x200, "WM_MOUSEMOVE")

Global hGui, hGui2

Gui, +hWndhGui

Loop, 5
   Gui, Add, Button, w60 h20, G1 %A_Index%

Gui 2: +Parent1 +hWndhGui2 -Caption

Loop, 5
   Gui, 2:Add, Button, x50 w60 h20, G2 %A_Index%


Gui, 2:Show, x0 y0
Gui, Show, w400 h300
Return



WM_MOUSEMOVE(wParam, lParam, msg, hWnd) {

   X := lParam & 0xFFFF   
   Y := (lParam >> 16)

   FileAppend, X: %X% Y: %Y%`n,*

   hWnd := Format("{:#x}", hWnd)
   ;FileAppend, hGui: %hGui% hWnd: %hWnd%`n,*



   CoordMode, Mouse, Client
   MouseGetPos, X, Y

   FileAppend, X: %X% Y: %Y%`n,*



   static CWP_ALL        := 0x0000
   , CWP_SKIPINVISIBLE   := 0x0001
   , CWP_SKIPDISABLED    := 0x0002
   , CWP_SKIPTRANSPARENT := 0x0004

   hwnd := DllCall("ChildWindowFromPointEx"
	, "Ptr", hGui
   , "Int64", (x & 0xFFFFFFFF) | (y << 32)
	, "UInt", CWP_ALL
	, "Ptr")

   hWnd := Format("{:#x}", hWnd)



   WinGetClass, WinClass, ahk_id %hWnd%
   FileAppend,  WinClass: %WinClass% `n,*
   FileAppend, => hwnd: %hwnd%`nhGui: %hGui% hGui2: %hGui2%`n`n,*

   If (WinClass = "Button")
      WinHide, ahk_id %hWnd%



   ; ==============================================
   ; ==============================================

   Point := (Y << 32) | (X & 0xFFFFFFFF)
   hWnd2 :=  DllCall("ChildWindowFromPointEx", "Ptr", hGui, "Int64", Point, "UInt", 0x05, "UPtr")
   hWnd2 := Format("{:#x}", hWnd2)

   WinGetClass, WinClass, ahk_id %hWnd2%
   FileAppend,  WinClass: %WinClass% `n,*
   FileAppend, => hwnd2: %hwnd2%`nhGui: %hGui% hGui2: %hGui2%`n`n,*



}



Esc::ExitApp
When i hover over the controls of the Gui2, the hWnd being returned belongs to the Gui2 itself
instead of the control
The return value is a handle to the first child window that contains the point and meets the criteria specified by uFlags. If the point is within the parent window but not within any child window that meets the criteria, the return value is a handle to the parent window. If the point lies outside the parent window or if the function fails, the return value is NULL.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: tiska and 105 guests