WinGetTitle Topic is solved

Report problems with documented functionality
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

WinGetTitle

07 Oct 2023, 07:29

Possible WinGetTitle bug.
User avatar
andymbody
Posts: 957
Joined: 02 Jul 2017, 23:47

Re: WinGetTitle

07 Oct 2023, 09:09

See this post for possible explanation...

viewtopic.php?f=83&t=113308&p=542257#p542257
theyakutoo
Posts: 14
Joined: 09 Sep 2023, 11:15

Re: WinGetTitle

08 Oct 2023, 23:44

Same error with WinGetPos...

Checking for previous posts about this issue... and found my own post quoted! Thanks for putting this in bug reports :)
lexikos
Posts: 9679
Joined: 30 Sep 2013, 04:07
Contact:

Re: WinGetTitle

09 Oct 2023, 21:38

What makes you think it is a bug? If there is no foreground window (the system function GetForegroundWindow returns 0), or the foreground window cannot be "found" due to DetectHiddenWindows, there will be no target window. Hence the error. WinExist("A") should be 0 in these cases.

@andymbody It does not matter what the title is. There is no such thing as a window with no title, but sometimes the title is not visible, or has a length of 0.
User avatar
andymbody
Posts: 957
Joined: 02 Jul 2017, 23:47

Re: WinGetTitle

09 Oct 2023, 21:51

lexikos wrote:
09 Oct 2023, 21:38
How do we avoid the exception/error that is thrown, other than try/catch?
lexikos
Posts: 9679
Joined: 30 Sep 2013, 04:07
Contact:

Re: WinGetTitle

10 Oct 2023, 02:02

You don't avoid an exception that is thrown. You catch it, or you avoid the condition that causes the exception to be thrown, so that it isn't thrown.

As I said, WinExist("A") should return 0 in those cases.
theyakutoo
Posts: 14
Joined: 09 Sep 2023, 11:15

Re: WinGetTitle

11 Oct 2023, 03:36

It seems like a bug because V1 did not behave this way.

I'll use a lib to handle the V2 window title oddities.

Code: Select all

#Requires AutoHotkey >2
#Singleinstance force

wX1:=0,wY1:=0,wXd:=0,wYd:=0
while 1 {
	wGetPos(&wX1, &wY1, &wXd, &wYd, "A")
	tooltip(wGetTitle("A") '`n' wX1 "," wY1 "`n" wXd "," wYd "`n" a_tickcount)
	sleep 100
}

esc::exitapp

;=============================================================================
; wGetTitle
;=============================================================================
wGetTitle(title) {		; ahk2 has issue with getting title for taskbar when switching apps.
	try	return WinGetTitle(title)
	catch
		return ""
}

;=============================================================================
; wGetPos
;=============================================================================
wGetPos(&pX1, &pY1, &pXd, &pYd, title) {
	try	return WinGetPos(&pX1, &pY1, &pXd, &pYd, title)
	catch {
		pX1:=0,pY1:=0,pXd:=0,pYd:=0
		return 0
	}
}
lexikos
Posts: 9679
Joined: 30 Sep 2013, 04:07
Contact:

Re: WinGetTitle  Topic is solved

11 Oct 2023, 20:55

What do you think is the point of changing the version number? Of course it behaves differently.
WinGetTitle v1 wrote:If there is no matching window, OutputVar is made blank.
WinGetTitle v2 wrote:A TargetError is thrown if the window could not be found.
This is part of overall changes to error handling. v1 has a tendency to ignore errors, return blank values or set ErrorLevel; it is inconsistent. v2 throws errors more consistently.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 16 guests