Get List of All Hidden Windows

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WalterRoberts
Posts: 67
Joined: 25 Feb 2020, 20:00

Get List of All Hidden Windows

23 Jun 2021, 11:43

As far as I know there is no other way than first getting the list of visible windows, then getting the list of hidden windows and then subtracting the visible window list from the hidden one.
I have used this simple algorithms to achieve this:

Code: Select all

^h::
	DetectHiddenWindows, Off
	WinGet, VisibleID, List,,, Program Manager
	DetectHiddenWindows, On
	WinGet, CombinedID, List,,, Program Manager
	i := 1, k := 1
	Loop, %CombinedID%
	{
		j := 1
		Loop, %VisibleID%
		{
			if (CombinedID%i% = VisibleID%j%)
				break
			else
				j++
		}
		
		if (j > VisibleID) {
			HiddenID%k% := CombinedID%i%
			k++
		}
		i++
	}
	HiddenID := k - 1
return
Is there another way of doing this?
Also, is it possible to avoid pseudo-arrays altogether?
I tried to do so, but didn't get it to work with regular arrays. Maybe this is not possible because WinGet is always going to return a pseudo-array...
It should be possible though to output HiddenID as a regular array? Could the total number of hidden windows then still be stored in a regular array? Edit: I mean stored in a way like HiddeID[0] := total_number_of_hidden_windows.
User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: Get List of All Hidden Windows

23 Jun 2021, 11:52

Your other arrays don’t need to be pseudo-arrays just because that’s the form the list is in. Also, you can immediately assign the elements of the pseudo-array to an array object so you don’t have to deal with the pseudo-array at all after that. See the documentation on Objects, especially the section on Simple Arrays, to see how you assign and retrieve elements to/from an array.

Once you have an array object, you get a count using HiddenID.Count(), not from the zeroth element of the array.
User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: Get List of All Hidden Windows

23 Jun 2021, 12:33

You don't need to get the two lists and compare them. You can determine if the window is visible or not and only add it to the array if it's not:

Code: Select all

HiddenID := []
DetectHiddenWindows, On
WinGet, AllID, List,,, Program Manager
loop, % AllID {
	WinGet, Style, Style, % "ahk_id" AllID%A_Index%
	if !(Style & 0x10000000) ; 0x10000000 is WS_VISIBLE
		HiddenID.Push(AllID%A_Index%)
}
HiddenWindows := "There are " HiddenID.Count() " hidden windows:`n`n"
for Each, ID in HiddenID {
	WinGetTitle, Title, ahk_id %ID%
	HiddenWindows .= ID "`t" Title "`n"
}
MsgBox, % HiddenWindows
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Get List of All Hidden Windows

23 Jun 2021, 13:02

except a hidden window by ahk's standards is one thats not visible or is cloaked:

Code: Select all

isWindowHidden(hwnd) {
	static DwmGetWindowAttribute := DllCall("GetProcAddress", "Ptr", DllCall("LoadLibrary", "Str", "dwmapi.dll", "Ptr"), "AStr", "DwmGetWindowAttribute", "Ptr")

	if DwmGetWindowAttribute
		hr := DllCall(DwmGetWindowAttribute
			, "Ptr", hwnd
			, "UInt", 14 ; DWMWA_CLOAKED
			, "Int*", cloakedType := 0
			, "UInt", 4)

	return !DllCall("IsWindowVisible", "Ptr", hwnd) || (!hr && cloakedType)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: NinjoOnline and 295 guests