Loop ID%A_Index%, how to restart in case of changes?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Loop ID%A_Index%, how to restart in case of changes?

20 May 2020, 13:30

Hi guys, I need your help.
I would like to draw some text on the windows that are of a certain group.

Code: Select all

GroupAdd, CLASSE, ahk_class ....
WinGet, ID, List , ahk_group CLASSE
Loop %ID%
{
	this_id := ID%A_Index%
	WinGetTitle, this_title, ahk_id %this_id%
	WinGetPos, X, Y,,, %this_title%
	Gui, ID%A_Index%:+toolwindow -caption +AlwaysOnTop
	Gui, ID%A_Index%:Font, s20 Verdana
	Gui, ID%A_Index%:Add, Text, x5 y5 cRed +BackgroundTrans, %this_title%
	Gui, ID%A_Index%:Color, white
	Y := Y+150
	X := X+500
	Gui, ID%A_Index%:Show, x%X% y%Y% NoActivate, Titolo
	WinSet, TransColor, white 200, Titolo
}
Return
In this way, however, it's not sensitive to changes.

I would like to restart the loop in case a group window changes its title or is closed to be replaced.
How should I proceed?

The approach with "Reload" I see it too forced, it takes up a lot of resources, and is not sensitive to changes but simply reloads the script.

Thanks so much
User avatar
littlegandhi1199
Posts: 195
Joined: 29 Aug 2016, 23:58

Re: Loop ID%A_Index%, how to restart in case of changes?

30 May 2020, 14:55

Does this work for ya?

Code: Select all

GroupAdd, CLASSE, ahk_class ....

Top:
WinGet, ID, List , ahk_group CLASSE
Loop %ID%
{
	Max := A_Index
	this_id := ID%A_Index%
	WinGetTitle, this_title, ahk_id %this_id%
	WinGetPos, X, Y,,, %this_title%
	Gui, ID%A_Index%:+toolwindow -caption +AlwaysOnTop
	Gui, ID%A_Index%:Font, s20 Verdana
	Gui, ID%A_Index%:Add, Text, x5 y5 cRed +BackgroundTrans, %this_title%
	Gui, ID%A_Index%:Color, white
	Y := Y+150
	X := X+500
	Gui, ID%A_Index%:Show, x%X% y%Y% NoActivate, Titolo
	WinSet, TransColor, white 200, Titolo
}


loop
{
WinGet, ID, List , ahk_group CLASSE
Loop %ID%
	newmax := A_Index
If (newmax < Max)
	break
}

loop, Max
	Gui, ID%A_Index%:Destroy

If (newmax < Max)
	goto Top
Return
Script Backups on every Execution :mrgreen:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=75767&p=328155#p328155

Scrabble Solver 4-15 letter word outputs ( :crazy: # of inputs)
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=34285
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Loop ID%A_Index%, how to restart in case of changes?

31 May 2020, 14:11

littlegandhi1199 wrote:
30 May 2020, 14:55
Does this work for ya?
Hi littlegandhi1199, thank you.

It works until I close or open new group's windows, from then on overwriting multiple titles in the same position.
In addition, each new group's window opened, sets all previous titles as title design, draws the titles one above the other. :(

Image
User avatar
littlegandhi1199
Posts: 195
Joined: 29 Aug 2016, 23:58

Re: Loop ID%A_Index%, how to restart in case of changes?

31 May 2020, 14:20

teosc wrote:
31 May 2020, 14:11
littlegandhi1199 wrote:
30 May 2020, 14:55
Does this work for ya?
Hi littlegandhi1199, thank you.

It works until I close or open new group's windows, from then on overwriting multiple titles in the same position.
In addition, each new group's window opened, sets all previous titles as title design, draws the titles one above the other. :(

Image
Okay I had no way of testing it really. I'm not all that familiar with window groups either.
Could you send me the full code. It looks really cool!

I'll figure it out.
I'm sure it's something easy
Script Backups on every Execution :mrgreen:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=75767&p=328155#p328155

Scrabble Solver 4-15 letter word outputs ( :crazy: # of inputs)
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=34285
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Loop ID%A_Index%, how to restart in case of changes?

31 May 2020, 14:30

littlegandhi1199 wrote:
31 May 2020, 14:20
Okay I had no way of testing it really. I'm not all that familiar with window groups either.
Could you send me the full code. It looks really cool!

I'll figure it out.
I'm sure it's something easy
For now I am having the "reload" approach but it is clearly a cheat:

Code: Select all

#NoEnv
#SingleInstance Force
#NoTrayIcon

GroupAdd, Chrome, ahk_class Chrome_WidgetWin_1
WinGet, ID, List , ahk_group Chrome
Loop %ID%
{
	this_id := ID%A_Index%
	WinGetTitle, this_title, ahk_id %this_id%
	WinGetPos, X, Y,,, %this_title%
	Gui, ID%A_Index%:+toolwindow -caption +AlwaysOnTop
	Gui, ID%A_Index%:Font, s20 Verdana
	Gui, ID%A_Index%:Add, Text, x5 y5 cRed +BackgroundTrans, %this_title%
	Gui, ID%A_Index%:Color, white
	Y := Y+150
	X := X+230
	Gui, ID%A_Index%:Show, x%X% y%Y% NoActivate, Titolo
	WinSet, TransColor, white 200, Titolo
}
Sleep, 10000
Reload
Return
User avatar
littlegandhi1199
Posts: 195
Joined: 29 Aug 2016, 23:58

Re: Loop ID%A_Index%, how to restart in case of changes?

31 May 2020, 16:39

There you go. Update is how often to double check windows.
If the window title changes it destroys everything and recreates it.
However if the position changes it just scoots it around.

Of course it doesn't care whether the window is minimized or not or if a previous window is entirely covered up.
Didn't add it in because I wasn't sure you wanted it.

Added in option which lets you click through the gui overlays "+E0x20" found that recently. Pretty nice

Code: Select all

#NoEnv
#SingleInstance Force
#NoTrayIcon

update := 500

GroupAdd, Chrome, ahk_class Chrome_WidgetWin_1

Top:
ListWindows = 
WinGet, ID, List , ahk_group Chrome
Loop %ID%
{
	Max := A_Index
	this_id := ID%A_Index%
	WinGetTitle, this_title, ahk_id %this_id%
	WinGetPos, X, Y,,, ahk_id %this_id%
	
	ListWindows = %ListWindows%%this_title%%A_Tab%%this_id%%A_Tab%%X%%A_Tab%%Y%`n
	
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+E0x20 option lets you click through the GUI which I like
	Gui %A_Index%:+toolwindow -caption +AlwaysOnTop +E0x20
	Gui %A_Index%:Font, s20 Verdana
	Gui %A_Index%:Add, Text, x5 y5 cRed +BackgroundTrans, %this_title%
	Gui %A_Index%:Color, white
	Y := Y+150
	X := X+500
	Gui %A_Index%:Show, x%X% y%Y% NoActivate, Titolo
	WinSet, TransColor, white 200, Titolo
}


loop
{
sleep %update%
WinGet, ID, List , ahk_group Chrome
Loop %ID%
	newmax := A_Index
If (newmax != Max)
	break

reset = 0
;;msgbox, checking windows
Loop, Parse, ListWindows, `n
{
out := A_Loopfield
checkINDEX := A_Index
Loop, parse, out, %A_Tab%
{
If (A_Index = 1)
	Title := A_Loopfield
Else If (A_Index = 2)
	this_id := A_Loopfield
Else If (A_Index = 3)
	X := A_Loopfield
Else If (A_Index = 4)
	Y := A_Loopfield
}
WinGetTitle, this_title, ahk_id %this_id%
WinGetPos, newX, newY,,, ahk_id %this_id%
If (this_title != Title)
{
reset = 1
break
}
Else If ((newX != X) || (newY != Y))
{
;;msgbox, moving it
X := newX+500
Y := newY+150
Gui %checkINDEX%:Show, x%X% y%Y% NoActivate, Titolo
}
}
;;msgbox, checked "%checkINDEX%" windows
If (Reset = 1)
	break
}

loop, %Max%
	Gui %A_Index%:Destroy

;;msgbox, Destroyed going to top...now %newmax% windows
goto Top
Return
Script Backups on every Execution :mrgreen:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=75767&p=328155#p328155

Scrabble Solver 4-15 letter word outputs ( :crazy: # of inputs)
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=34285

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: arrondark, mikeyww, Tech Stuff and 202 guests