Question About DetectHiddenWindows Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Question About DetectHiddenWindows

Post by Mulsiphix » 29 Mar 2022, 14:01

I found this code for centering ToolTips on the forum. Why is it that the code fails when DetectHiddenWindows, On is set? I read the documentation for DetectHiddenWindows, but still do not understand exactly how this command breaks the centering code.

Centers Properly

Code: Select all

ToolTip, % "SampleTextSampleTextSampleTextSampleTextSampleTextSampleTextSampleText`n`n`nSampleTextSample"
toolHwnd := "ahk_id" . WinExist("ahk_class tooltips_class32")
WinGetPos, x, y, w, h, % toolHwnd
toolX := (A_ScreenWidth - w) // 2
toolY := (A_ScreenHeight - h) // 2
WinMove, % toolHwnd, , % toolX, % toolY 

Esc::ExitApp
Doesn't Align

Code: Select all

DetectHiddenWindows, On
ToolTip, % "SampleTextSampleTextSampleTextSampleTextSampleTextSampleTextSampleText`n`n`nSampleTextSample"
toolHwnd := "ahk_id" . WinExist("ahk_class tooltips_class32")
WinGetPos, x, y, w, h, % toolHwnd
toolX := (A_ScreenWidth - w) // 2
toolY := (A_ScreenHeight - h) // 2
WinMove, % toolHwnd, , % toolX, % toolY 

Esc::ExitApp

RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Question About DetectHiddenWindows

Post by RussF » 29 Mar 2022, 14:29

Try:

Code: Select all

DetectHiddenWindows, On
toolX := (A_ScreenWidth) // 2
toolY := (A_ScreenHeight) // 2
ToolTip, % "SampleTextSampleTextSampleTextSampleTextSampleTextSampleTextSampleText`n`n`nSampleTextSample", toolx, tooly

Esc::ExitApp
Granted, it doesn't exactly center it, but it's close.

Russ

Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Re: Question About DetectHiddenWindows

Post by Mulsiphix » 29 Mar 2022, 14:34

Thank you @Russ. Can you explain specifically how DetectHiddenWindows interacts with the code in the original post? I would like to better understand how it breaks down and why.

User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: Question About DetectHiddenWindows  Topic is solved

Post by flyingDman » 29 Mar 2022, 16:56

Try this:

Code: Select all

DetectHiddenWindows, On

ToolTip, % "SampleTextSampleTextSampleTextSampleTextSampleTextSampleTextSampleText`n`n`nSampleTextSample"

WinGet, hwnd, List, ahk_class tooltips_class32
Loop, %hwnd%
	{
	WinGetTitle, Title, % "ahk_id " hwnd%A_Index%
	if Title
		WinGet, ID, ID, % Title
	}
toolHwnd := "ahk_id " . ID
WinGetPos, x, y, w, h, % toolHwnd
toolX := (A_ScreenWidth - w) // 2
toolY := (A_ScreenHeight - h) // 2
WinMove, % toolHwnd, , % toolX, % toolY 

Esc::ExitApp
Winexist returns the FIRST matching window. Tooltip (for some reason) spawns a whole bunch of hidden windows and the one we want is not the first one. When DetectHiddenWindows is OFF, these hidden windows are not detected. But, when it is ON Winexist gets the wrong one. The above addition detects which one is the "real" one.
14.3 & 1.3.7

Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Re: Question About DetectHiddenWindows

Post by Mulsiphix » 29 Mar 2022, 18:34

Interesting. How was it you were able to figure out the Tooltip was launching a bunch of windows? The script works wonderfully! Thank you so much :bravo:

User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: Question About DetectHiddenWindows

Post by flyingDman » 29 Mar 2022, 18:46

See how many windows are generated:

Code: Select all

DetectHiddenWindows, On

ToolTip, % "Hello World"
WinGet, hwnd, List, ahk_class tooltips_class32
Loop, %hwnd%
	{
	WinGetTitle, Title, % "ahk_id " hwnd%A_Index%
	msgbox % ">>" Title "<<"
	}	
All except one yield a ">><<" (an empty string).
14.3 & 1.3.7

Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Re: Question About DetectHiddenWindows

Post by Mulsiphix » 29 Mar 2022, 19:17

That is insane. I just ran your script and "Hello World" appeared on the 8th window. I clicked through 115 MsgBox's total. Thank you very much for your fix. And the education :bravo:

User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: Question About DetectHiddenWindows

Post by flyingDman » 29 Mar 2022, 19:34

Did you say 115 ? I have significanlty fewer - 21 to be exact. If there at that many, you might to break the loop when the "one" is found:

Code: Select all

DetectHiddenWindows, On

ToolTip, % "Hello World"

WinGet, hwnd, List, ahk_class tooltips_class32
Loop, %hwnd%
	{
	WinGetTitle, Title, % "ahk_id " hwnd%A_Index%
	if Title
		{
		WinGet, ID, ID, % Title
		break
		}
	}
toolHwnd := "ahk_id " . ID
WinGetPos, x, y, w, h, % toolHwnd
toolX := (A_ScreenWidth - w) // 2
toolY := (A_ScreenHeight - h) // 2
WinMove, % toolHwnd, , % toolX, % toolY 

Esc::ExitApp
14.3 & 1.3.7

RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Question About DetectHiddenWindows

Post by RussF » 30 Mar 2022, 06:01

Well done @flyingDman! :beer:

Russ

Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Re: Question About DetectHiddenWindows

Post by Mulsiphix » 04 Apr 2022, 11:09

flyingDman wrote:
29 Mar 2022, 18:46
See how many windows are generated:

Code: Select all

DetectHiddenWindows, On

ToolTip, % "Hello World"
WinGet, hwnd, List, ahk_class tooltips_class32
Loop, %hwnd%
	{
	WinGetTitle, Title, % "ahk_id " hwnd%A_Index%
	msgbox % ">>" Title "<<"
	}	
All except one yield a ">><<" (an empty string).


Another approach so you can see all of the windows that are created.

Code: Select all

DetectHiddenWindows, On

Gui, Add, ListView, w230 h300, #|Of|Win|ahk_id|Contents
ToolTip, % "Hello World"
WinGet, hwnd, List, ahk_class tooltips_class32
Loop, %hwnd%
{
    this_id := hwnd%A_Index%
    WinGetTitle, Title, % "ahk_id " hwnd%A_Index%
    LV_Add("", A_Index, "of", hwnd, this_id, Title)
}
LV_ModifyCol(1, "AutoHdr Right")
LV_ModifyCol(2, "Right")
LV_ModifyCol(3, "AutoHdr Left")
LV_ModifyCol(4, "AutoHdr Center")
LV_ModifyCol(5, "AutoHdr Left")
Gui, -MinimizeBox -MaximizeBox
Gui, Show,,List Of All Tooltip Windows
Return

Escape::
Reload

+Escape::
GuiClose:
ExitApp

Post Reply

Return to “Ask for Help (v1)”