I had to modify an old AHK basic script and needed to count the number of open windows.
No problem: WinGet , varTally, Count
What the ...! The count was many hundreds, sometimes in the thousands.
Manual count 1, 2, 3.
Three
Where did the rest reported by WinGet come from?
Used WinGet varList, List to list them all by name but many had no name.
Listed them by class and also by text - it appears to be counting controls within windows and also tooltips.
How can I get a count of just windows, real windows?
When is a window not a window? WinGet , Tally, Count
- Blue Kodiak
- Posts: 26
- Joined: 17 Mar 2019, 00:45
Re: When is a window not a window? WinGet , Tally, Count
You have probably DetectHiddenWindows, On in your script. If I use it, I get 246 windows, with it off only 16 (at this moment), but including things like the taskbar which is also a window, but easy to exclude...
Re: When is a window not a window? WinGet , Tally, Count
It seems that you have a somewhat blurred concept of what a window is. I think you mean the top-level visible windows.
https://docs.microsoft.com/en-us/windows/desktop/winmsg/windows.
https://docs.microsoft.com/en-us/windows/desktop/winmsg/about-windows.
https://docs.microsoft.com/en-us/windows/desktop/winmsg/windows.
https://docs.microsoft.com/en-us/windows/desktop/winmsg/about-windows.
Re: When is a window not a window? WinGet , Tally, Count
A control is a window.
Since you haven't clarified what you consider "real windows" to be, I can only speculate you meant the ones with visible titles.
WinGet, OutputVar, List doesn't list windows by name. It lists them by their handles.MSDN wrote:
- Occupies a certain portion of the screen.
- May or may not be visible at a given moment.
- Knows how to draw itself.
- Responds to events from the user or the operating system.
Since you haven't clarified what you consider "real windows" to be, I can only speculate you meant the ones with visible titles.
Code: Select all
WinGetList(WinTitle := "", WinText := "", ExcludeTitle := "", ExcludeText := "") {
hiddenWindows := A_DetectHiddenWindows
DetectHiddenWindows Off
Windows:= []
WinGet l, List, % WinTitle, % WinText, % ExcludeTitle, % ExcludeText
Loop % l
{
hwnd := l%A_Index%
WinGetTitle title, % "ahk_id" hwnd
if title
Windows.Push({hwnd: hwnd, title: title})
}
DetectHiddenWindows % hiddenWindows
return Windows
}
WinGetCount(WinTitle := "", WinText := "", ExcludeTitle := "", ExcludeText := "") {
return WinGetList(WinTitle, WinText, ExcludeTitle, ExcludeText).Count()
}
Who is online
Users browsing this forum: No registered users and 275 guests