WinGet WindowList.ahk - Not showing fullscreen windows

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Cariboudjan
Posts: 9
Joined: 14 Jul 2020, 21:12

WinGet WindowList.ahk - Not showing fullscreen windows

14 Jul 2020, 21:33

Annotation 2020-07-14 202845.png
Annotation 2020-07-14 202845.png (154.99 KiB) Viewed 2285 times
The above image and the below code shows list of running app windows and activates the window when clicked.
However, it filters out windows that do not have a title bar. This is a good thing and a bad thing. A good thing because it filters out things like the Nvidia Overlay and other invisible background apps, but it's a bad thing because it also filters out things I do want, like fullscreen games running in the background.

I'm wondering if there's a way to modify this code to show a proper list of apps as it shows properly in the alt+tab window or as displayed in the windows task bar. If this is a limitation of AHK and not possible, please let me know.

Bonus question: I'm also looking for a way to filter out items from the list that have a specific window title.

Code: Select all

#SingleInstance, Ignore
#NoTrayIcon

OnExit, ExitSub

Try
{
Menu, Windows, Add
Menu, Windows, deleteAll
WinGet windows, List
Loop %windows%
{
	Menu, Windows, Add, Open Windows Task View..., Activate_Taskview
	Menu, Windows, Icon, Open Windows Task View..., %A_ScriptDir%\TaskView.ico,, %3%
	id := windows%A_Index%
	WinGetTitle, title, ahk_id %id%
	WinGetClass, class, ahk_id %id%	
	If (class = "ApplicationFrameWindow") 
	{
		WinGetText, text, ahk_id %id%
		If (text = "")
			continue
	} 
	WinGet, style, style, ahk_id %id%
	If !(style & 0xC00000) ; if the window doesn't have a title bar
	{
		; If title not contains ...  ; add exceptions
			continue
	}
	WinGet, Path, ProcessPath, ahk_id %id%

	Menu, Windows, Add, %title%, Activate_Window
    If (class  = "ApplicationFrameWindow")
        Menu, Windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
    else
        Menu, Windows, Icon, %title%, %Path%,, %3%
}
Menu, Windows, Show, %1%, %2%
return

Activate_Taskview:
	SetStoreCapsLockMode, Off
	Send, #{Tab}
	Run, "%PROGRAMFILES%\Rainmeter\Rainmeter.exe" !Update "Droptop\BackgroundProcesses"
return

Activate_Window:
	SetTitleMatchMode, 3
	WinActivate, %A_ThisMenuItem%
	Run, "%PROGRAMFILES%\Rainmeter\Rainmeter.exe" !Update "Droptop\BackgroundProcesses"
return
}

ExitSub:
	Run, "%PROGRAMFILES%\Rainmeter\Rainmeter.exe" !UpdateMeasure IsFull "Droptop\BackgroundProcesses"
ExitApp
User avatar
Maestr0
Posts: 136
Joined: 05 Dec 2013, 17:43

Re: WinGet WindowList.ahk - Not showing fullscreen windows

15 Jul 2020, 02:10

Hi there,

Right now, your script actively ignores any windows that don't have title bars (see line 25).

I don't know which windows you have issues with, so I can't test it, but I think you can get around it by adding a check to see if the window in question is maximized, using Winget MinMax: https://www.autohotkey.com/docs/commands/WinGet.htm#MinMax

Here, try the code below, I've added comments to the code I've added. I could not properly test the code, so let me know what you find:

Code: Select all

#SingleInstance, Ignore
#NoTrayIcon

OnExit, ExitSub

ignore_list := "Paint,Calculator" ; if the titlebar contains any (part) of these words, it will not be shown

Try
{
Menu, Windows, Add
Menu, Windows, deleteAll
WinGet windows, List
Loop %windows%
{
	Menu, Windows, Add, Open Windows Task View..., Activate_Taskview
	Menu, Windows, Icon, Open Windows Task View..., %A_ScriptDir%\TaskView.ico,, %3%
	id := windows%A_Index%
	WinGetTitle, title, ahk_id %id%
	if ( title contains ignore_list ) ; this checks if the title has any part of the listed words to ignore in the ignore_list variable above
		continue
	WinGetClass, class, ahk_id %id%	
	If (class = "ApplicationFrameWindow") 
	{
		WinGetText, text, ahk_id %id%
		If (text = "")
			continue
	} 
	WinGet, minmax, MinMax, ahk_id %id%
	if ( minmax != 1 ) ; minmax = 1 means it's maximized, so here we only check the part below if it's NOT 1
	{
		WinGet, style, style, ahk_id %id%
		If !(style & 0xC00000) ; if the window doesn't have a title bar
		{
			; If title not contains ...  ; add exceptions
				continue
		}
	}
	WinGet, Path, ProcessPath, ahk_id %id%

	Menu, Windows, Add, %title%, Activate_Window
    If (class  = "ApplicationFrameWindow")
        Menu, Windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
    else
        Menu, Windows, Icon, %title%, %Path%,, %3%
}
Menu, Windows, Show, %1%, %2%
return

Activate_Taskview:
	SetStoreCapsLockMode, Off
	Send, #{Tab}
	Run, "%PROGRAMFILES%\Rainmeter\Rainmeter.exe" !Update "Droptop\BackgroundProcesses"
return

Activate_Window:
	SetTitleMatchMode, 3
	WinActivate, %A_ThisMenuItem%
	Run, "%PROGRAMFILES%\Rainmeter\Rainmeter.exe" !Update "Droptop\BackgroundProcesses"
return
}

ExitSub:
	Run, "%PROGRAMFILES%\Rainmeter\Rainmeter.exe" !UpdateMeasure IsFull "Droptop\BackgroundProcesses"
ExitApp
Cariboudjan
Posts: 9
Joined: 14 Jul 2020, 21:12

Re: WinGet WindowList.ahk - Not showing fullscreen windows

21 Jul 2020, 15:32

It doesn't seem to work.

Doesn't show any apps at all. Maybe I missed something?

Annotation 2020-07-21 143220.png
Annotation 2020-07-21 143220.png (13.12 KiB) Viewed 1406 times
Maestr0 wrote:
15 Jul 2020, 02:10
Hi there,

Right now, your script actively ignores any windows that don't have title bars (see line 25).

I don't know which windows you have issues with, so I can't test it, but I think you can get around it by adding a check to see if the window in question is maximized, using Winget MinMax: https://www.autohotkey.com/docs/commands/WinGet.htm#MinMax

Here, try the code below, I've added comments to the code I've added. I could not properly test the code, so let me know what you find:

Code: Select all

#SingleInstance, Ignore
#NoTrayIcon

OnExit, ExitSub

ignore_list := "Paint,Calculator" ; if the titlebar contains any (part) of these words, it will not be shown

Try
{
Menu, Windows, Add
Menu, Windows, deleteAll
WinGet windows, List
Loop %windows%
{
	Menu, Windows, Add, Open Windows Task View..., Activate_Taskview
	Menu, Windows, Icon, Open Windows Task View..., %A_ScriptDir%\TaskView.ico,, %3%
	id := windows%A_Index%
	WinGetTitle, title, ahk_id %id%
	if ( title contains ignore_list ) ; this checks if the title has any part of the listed words to ignore in the ignore_list variable above
		continue
	WinGetClass, class, ahk_id %id%	
	If (class = "ApplicationFrameWindow") 
	{
		WinGetText, text, ahk_id %id%
		If (text = "")
			continue
	} 
	WinGet, minmax, MinMax, ahk_id %id%
	if ( minmax != 1 ) ; minmax = 1 means it's maximized, so here we only check the part below if it's NOT 1
	{
		WinGet, style, style, ahk_id %id%
		If !(style & 0xC00000) ; if the window doesn't have a title bar
		{
			; If title not contains ...  ; add exceptions
				continue
		}
	}
	WinGet, Path, ProcessPath, ahk_id %id%

	Menu, Windows, Add, %title%, Activate_Window
    If (class  = "ApplicationFrameWindow")
        Menu, Windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
    else
        Menu, Windows, Icon, %title%, %Path%,, %3%
}
Menu, Windows, Show, %1%, %2%
return

Activate_Taskview:
	SetStoreCapsLockMode, Off
	Send, #{Tab}
	Run, "%PROGRAMFILES%\Rainmeter\Rainmeter.exe" !Update "Droptop\BackgroundProcesses"
return

Activate_Window:
	SetTitleMatchMode, 3
	WinActivate, %A_ThisMenuItem%
	Run, "%PROGRAMFILES%\Rainmeter\Rainmeter.exe" !Update "Droptop\BackgroundProcesses"
return
}

ExitSub:
	Run, "%PROGRAMFILES%\Rainmeter\Rainmeter.exe" !UpdateMeasure IsFull "Droptop\BackgroundProcesses"
ExitApp
User avatar
Maestr0
Posts: 136
Joined: 05 Dec 2013, 17:43

Re: WinGet WindowList.ahk - Not showing fullscreen windows

23 Jul 2020, 13:06

What do you see when you do this:

Code: Select all

WinGet, id, List,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinGetClass, this_class, ahk_id %this_id%
    WinGetTitle, this_title, ahk_id %this_id%
    list .= A_Index " of " id " ahk_id " this_id " ahk_class " this_class " " this_title "`n"
}
msgbox % list
Cariboudjan
Posts: 9
Joined: 14 Jul 2020, 21:12

Re: WinGet WindowList.ahk - Not showing fullscreen windows

23 Jul 2020, 22:50

I get this. Fullscreen apps are visible in this list since it's not filtering out any fullscreen windows, but again that also means it's not filtering out other things, like invisible windows that are supposed to be hidden and do not appear in the taskbar.

Basically I just need it to show a list of apps identical to what is shown as running as shown on the taskbar.

Annotation 2020-07-23 215021.png
Annotation 2020-07-23 215021.png (59.75 KiB) Viewed 995 times
User avatar
Maestr0
Posts: 136
Joined: 05 Dec 2013, 17:43

Re: WinGet WindowList.ahk - Not showing fullscreen windows

24 Jul 2020, 06:50

Cariboudjan wrote:
23 Jul 2020, 22:50
I get this. Fullscreen apps are visible in this list since it's not filtering out any fullscreen windows, but again that also means it's not filtering out other things, like invisible windows that are supposed to be hidden and do not appear in the taskbar.

Basically I just need it to show a list of apps identical to what is shown as running as shown on the taskbar.
Ok, so we know the code we have shows everything, we now take that as a base and edit it to show what we want. When we have that, we change THAT code to fill the menu like you were trying before.

Now, try this and see if it only shows the windows that you want:

Code: Select all

#Persistent

exceptions := ["SciTEAutoHotkey","Spotify.exe"]

WinGet, id, List,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinGetClass, this_class, ahk_id %this_id%
    WinGetTitle, this_title, ahk_id %this_id%
    WinGet, this_processname, ProcessName, ahk_id %this_id%
	
	if (this_title = "")
		continue
	if HasVal(exceptions,this_processname)
	{
		; If title is in the exceptions list, skip it
		continue
	}
	
	If (class = "ApplicationFrameWindow") 
	{
		WinGetText, text, ahk_id %this_id%
		If (text = "")
			continue
	} 
	WinGet, style, style, ahk_id %this_id%
	If !(style & 0xC00000) ; if the window doesn't have a title bar
	{
		continue
	}
	
    list .= A_Index " of " id " ahk_id " this_id " ahk_class " this_class " " this_title " processname " this_processname "`n`n"
}
msgbox % list

HasVal(haystack, needle) {
	if !(IsObject(haystack)) || (haystack.Length() = 0)
		return 0
	for index, value in haystack
		if (value = needle)
			return index
	return 0
}
update

Code: Select all

#Persistent

exceptions := ["SciTE4AutoHotkey","Spotify.exe"]

WinGet, id, List,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinGetClass, this_class, ahk_id %this_id%
    WinGetTitle, this_title, ahk_id %this_id%
    WinGet, this_processname, ProcessName, ahk_id %this_id%
	
	if (this_title = "")
		continue
	if HasVal(exceptions,this_processname) OR HasVal(exceptions,this_title)
	{
		; If title is in the exceptions list, do not add it
		continue
	}
	
	If (class = "ApplicationFrameWindow") 
	{
		WinGetText, text, ahk_id %this_id%
		If (text = "")
			continue
	} 
	WinGet, style, style, ahk_id %this_id%
	If !(style & 0xC00000) ; if the window doesn't have a title bar
	{
		continue
	}
	
    list .= A_Index " of " id " ahk_id " this_id " ahk_class " this_class " " this_title " processname " this_processname "`n`n"
}
msgbox % list

HasVal(haystack, needle) {
	if !(IsObject(haystack)) || (haystack.Length() = 0)
		return 0
	for index, value in haystack
	{
		; if (value = needle) ; this is exact matching
		if InStr(needle,value) ; this is true if part of the value (exception) is in the needle
			return index
	}
	return 0
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Chunjee and 139 guests