List all open and visible window (Alt+Tab) in windwos 10 Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

List all open and visible window (Alt+Tab) in windwos 10

03 Jul 2018, 11:46

Hi,
I'm trying to list all open and visible window (minimized one also count) using following code (this code is not mine),

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, RegEx
DetectHiddenWindows, Off
WinGet windows, List
Loop %windows%
{
	id := windows%A_Index%
	WinGetTitle wt, ahk_id %id%
	r .= wt . "`n"
}
MsgBox %r%
Though it list all open window, it also list inactive non visible window (those were not running when I run this script) in windows 10 like Calculator, Microsoft Edge, Photos, Store... etc. From what I've come to know is windows 10 use ApplicationFrameHost to display or run those widow. Is there any way to list only visible (minimized one also count) window like Alt+Tab window?

Best Regards,
Sobuj
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: List all open and visible window (Alt+Tab) in windwos 10

03 Jul 2018, 12:01

check your system and you will see if it shows calculator you have calculator.exe running etc
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: List all open and visible window (Alt+Tab) in windwos 10

03 Jul 2018, 12:23

winget,,list... shows a lot of things that are not in the alt-tab window. it's not just him. It's an ahk/os thing. iirc, It's tricky to get what he wants.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

Re: List all open and visible window (Alt+Tab) in windwos 10

03 Jul 2018, 14:22

AHKStudent wrote:check your system and you will see if it shows calculator you have calculator.exe running etc
Thanks for your replay. As I've mentioned, it was not running well at least not visible. My goal is to list only visible windows (Minimized in task bar also counts). I've also tried this code https://autohotkey.com/board/topic/9191 ... lose-them/. But it list inactive invisible window
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

Re: List all open and visible window (Alt+Tab) in windwos 10

03 Jul 2018, 14:26

tidbit wrote:winget,,list... shows a lot of things that are not in the alt-tab window. it's not just him. It's an ahk/os thing. iirc, It's tricky to get what he wants.
:) Windows 10 made life harder
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: List all open and visible window (Alt+Tab) in windwos 10

03 Jul 2018, 15:34

best way I can think of, get everything before "system \n system" and remove any blank lines.

for me, running your code, has 2 "system" items in a row, and all of my windows were above that.
Will it be 100% reliable? no idea. but it's worth a shot if you have the same results.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: List all open and visible window (Alt+Tab) in windwos 10

03 Jul 2018, 17:18

Try also

Code: Select all

WinGet windows, List
Loop %windows%
{
	id := windows%A_Index%
	WinGetTitle title, ahk_id %id%
	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
	}
	r .= title . "`n"
}
MsgBox %r%
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 00:53

GEV wrote:Try also

Code: Select all

WinGet windows, List
Loop %windows%
{
	id := windows%A_Index%
	WinGetTitle title, ahk_id %id%
	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
	}
	r .= title . "`n"
}
MsgBox %r%
Thanks for your reply but as you can see Image marked item was not running (well atleast not visible in taskbar). But still they were listed.
Last edited by sobuj53 on 04 Jul 2018, 01:00, edited 1 time in total.
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 00:56

tidbit wrote:best way I can think of, get everything before "system \n system" and remove any blank lines.

for me, running your code, has 2 "system" items in a row, and all of my windows were above that.
Will it be 100% reliable? no idea. but it's worth a shot if you have the same results.
Can you please provide the code. I didn't get the part "system \n system".
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 03:39

If you don’t want Windows 10 Apps running in the background, you can disable this feature:
https://www.howtogeek.com/241752/how-to ... ackground/

Try also:

Code: Select all

WinGet windows, List
Loop %windows%
{
	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
	}
	r .= title . "`n"
}
MsgBox %r%
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 05:14

GEV wrote:If you don’t want Windows 10 Apps running in the background, you can disable this feature:
https://www.howtogeek.com/241752/how-to ... ackground/

Try also:

Code: Select all

WinGet windows, List
Loop %windows%
{
	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
	}
	r .= title . "`n"
}
MsgBox %r%
Thanks, stoping Windows 10 Apps running in the background is an option to consider. Above code how ever don't register Windows 10 Apps when they are actually open and visible!

I have a solution that works without stoping background apps,

Code: Select all

^F::
ignored := { "Microsoft.Photos.exe":0, "WinStore.App.exe":0, "Video.UI.exe":0, "ApplicationFrameHost.exe":0, "Calculator.exe":0
, "WinStore.exe":0, "Avro Keyboard.exe":0, "SystemSettings.exe":0, "MicrosoftEdgeCP.exe":0, "MicrosoftEdge.exe":0 }

WinGet windows, List
Loop %windows%
{
	id := windows%A_Index%
	WinGetTitle title, ahk_id %id%
	WinGet ProcsName, ProcessName, ahk_id %id%
	
	if ignored.HasKey(ProcsName)=1  ; if the window doesn't have a title bar
	{	
		; If title not contains ...  ; add exceptions
		continue
	}
	r .= title . "`n"
}
MsgBox %r%

reload
return
But this means I'm permanently blacklisting those. It's not possible to list windows apps when they are visible in taskbar via this script. Hope there will be a option to detect them somedays.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 05:53

This works on my system Win10 Build 17134.137 (only windows apps visible in taskbar are shown on the menu):

Code: Select all

$F1::
Menu, Windows, Add
Menu, Windows, deleteAll
WinGet windows, List
Loop %windows%
{
	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%,, 0
}
Menu, Windows, Show
return

Activate_Window:
	SetTitleMatchMode, 3
	WinActivate, %A_ThisMenuItem%
return
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 06:25

GEV wrote:This works on my system Win10 Build 17134.137 (only windows apps visible in taskbar are shown on the menu):

Code: Select all

$F1::
Menu, Windows, Add
Menu, Windows, deleteAll
WinGet windows, List
Loop %windows%
{
	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%,, 0
}
Menu, Windows, Show
return

Activate_Window:
	SetTitleMatchMode, 3
	WinActivate, %A_ThisMenuItem%
return
Thank you very much. But this throws an error Error: Parameter #3 must not be blank in this case. at line 027

Code: Select all

Menu, Windows, Icon, %title%, %Path%,, 0
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 06:55

In that case try to find out what program/window is the cause for the error (AHK cannot find the path of the process or the executable file doesn't contain any icons) and use the same icon as in ApplicationFrameWindow:

Code: Select all

$F1::
Menu, Windows, Add
Menu, Windows, deleteAll
WinGet windows, List
Loop %windows%
{
	id := windows%A_Index%
	WinGetTitle title, ahk_id %id%
	If (title = "")
		continue
	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  the executable file doesn't contain any icons (replace "this_class" with the class of that window)
    If (class  = "ApplicationFrameWindow") || (class  = "this_class")
        Menu, Windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
    else
        Menu, Windows, Icon, %title%, %Path%,, 0
}
Menu, Windows, Show
return

Activate_Window:
	SetTitleMatchMode, 3
	WinActivate, %A_ThisMenuItem%
return
Last edited by GEV on 04 Jul 2018, 07:06, edited 1 time in total.
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 07:05

GEV wrote:In that case try to find out what program/window is the cause for the error (AHK cannot find the path of the process or the executable file doesn't contain any icons) and use the same icon as in ApplicationFrameWindow:

Code: Select all

$F1::
Menu, Windows, Add
Menu, Windows, deleteAll
WinGet windows, List
Loop %windows%
{
	id := windows%A_Index%
	WinGetTitle title, ahk_id %id%
	If (title = "")
		continue
	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  the executable file doesn't contain any icons (replace "this_class" with the class of that window)
    If (class  = "ApplicationFrameWindow") || (class  = "this_class")
        Menu, Windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
	 else
    If (class  = "this class")
        Menu, Windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
    else
        Menu, Windows, Icon, %title%, %Path%,, 0
}
Menu, Windows, Show
return

Activate_Window:
	SetTitleMatchMode, 3
	WinActivate, %A_ThisMenuItem%
return
This throws another error :? Image. I must be missing something. Just can't figure out what that is!
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 07:24

taskhostw.exe isn't a visible process/window unless you have DetectHiddenWindows On. Try the above code as a stand alone script.
You can also add this to the code:

Code: Select all

	...
	WinGet, Path, ProcessPath, ahk_id %id%
	SplitPath, Path,,,,name_no_ext
	If (name_no_ext= "taskhostw")
		continue
	Menu, Windows, Add, %title%, Activate_Window
	...
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 08:02

You're probably using a 32-bit AHK on a 64-bit Windows? Then some redirection occurs, which might cause issues: https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
Instead of manually adding exceptions to a default icon, wouldn't it be more reliable to use a Try/Catch:

Code: Select all

$F1::
Menu, Windows, Add
Menu, Windows, deleteAll
WinGet windows, List
Loop %windows%
{
	id := windows%A_Index%
	WinGetTitle title, ahk_id %id%
	If (title = "")
		continue
	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
	Try 
		Menu, Windows, Icon, %title%, %Path%,, 0
	Catch 
		Menu, Windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
}
Menu, Windows, Show
return

Activate_Window:
	SetTitleMatchMode, 3
	WinActivate, %A_ThisMenuItem%
return
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 08:29

GEV wrote:taskhostw.exe isn't a visible process/window unless you have DetectHiddenWindows On. Try the above code as a stand alone script.
You can also add this to the code:

Code: Select all

	...
	WinGet, Path, ProcessPath, ahk_id %id%
	SplitPath, Path,,,,name_no_ext
	If (name_no_ext= "taskhostw")
		continue
	Menu, Windows, Add, %title%, Activate_Window
	...
Thank you sir. This works great. I really appreciate your help and time on this. :thumbup:
sobuj53
Posts: 55
Joined: 19 Mar 2015, 16:08

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 08:32

Nextron wrote:You're probably using a 32-bit AHK on a 64-bit Windows? Then some redirection occurs, which might cause issues: https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
Instead of manually adding exceptions to a default icon, wouldn't it be more reliable to use a Try/Catch:

Code: Select all

$F1::
Menu, Windows, Add
Menu, Windows, deleteAll
WinGet windows, List
Loop %windows%
{
	id := windows%A_Index%
	WinGetTitle title, ahk_id %id%
	If (title = "")
		continue
	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
	Try 
		Menu, Windows, Icon, %title%, %Path%,, 0
	Catch 
		Menu, Windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
}
Menu, Windows, Show
return

Activate_Window:
	SetTitleMatchMode, 3
	WinActivate, %A_ThisMenuItem%
return
Thank your very much for help sir. This works neatly. :thumbup: Love this community never came back empty handed.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: List all open and visible window (Alt+Tab) in windwos 10

04 Jul 2018, 08:34

Nextron wrote:Instead of manually adding exceptions to a default icon, wouldn't it be more reliable to use a Try/Catch
:thumbup: :bravo:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: wpulford and 415 guests