When is a window not a window? WinGet , Tally, Count

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Blue Kodiak
Posts: 26
Joined: 17 Mar 2019, 00:45

When is a window not a window? WinGet , Tally, Count

23 Mar 2019, 05:22

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. :o
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?
gregster
Posts: 9021
Joined: 30 Sep 2013, 06:48

Re: When is a window not a window? WinGet , Tally, Count

23 Mar 2019, 05:51

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...
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: When is a window not a window? WinGet , Tally, Count

23 Mar 2019, 07:14

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.
User avatar
lvalkov
Posts: 58
Joined: 08 Mar 2019, 16:39

Re: When is a window not a window? WinGet , Tally, Count

23 Mar 2019, 09:50

A control is a window.
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.
WinGet, OutputVar, List doesn't list windows by name. It lists them by their handles.

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()
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot] and 315 guests