Count number of tabs in active window Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
paik1002
Posts: 352
Joined: 28 Nov 2015, 02:45

Count number of tabs in active window

05 Jun 2017, 06:54

I would like to count the number of tabs in the currently active window of an application?

How can I fix the following script?

Code: Select all

$^+!F12::
{
	winget, nTabs, count, A			; this does not work
	; winget, ID, list, A
	tooltip % nTabs
	return
}
User avatar
jeeswg
Posts: 6469
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Count number of tabs in active window

05 Jun 2017, 09:15

Which program are you trying to retrieve information for?

Some possibilities:

ControlGet
https://autohotkey.com/docs/commands/ControlGet.htm
SendMessage, 0x1304,,, SysTabControl321, WinTitle ; 0x1304 is TCM_GETITEMCOUNT.
TabCount = %ErrorLevel%
Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
paik1002
Posts: 352
Joined: 28 Nov 2015, 02:45

Re: Count number of tabs in active window

05 Jun 2017, 09:51

jeeswg wrote:Which program are you trying to retrieve information for?

Some possibilities:

ControlGet
https://autohotkey.com/docs/commands/ControlGet.htm
SendMessage, 0x1304,,, SysTabControl321, WinTitle ; 0x1304 is TCM_GETITEMCOUNT.
TabCount = %ErrorLevel%
Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947

Actually, I do not want to limit it to a specific application. It could be tabs for an Internet Explorer window, PDF document readers, etc.
On the otherhand, if a general solution for the above problem can not be rendered,
then is it possible to detect existence of multiple tabs, as an alternative solution.
User avatar
jeeswg
Posts: 6469
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Count number of tabs in active window  Topic is solved

05 Jun 2017, 10:12

TCM_GETITEMCOUNT or AccViewer/the Acc library are probably the way to go.
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

I plan to add some functions for IE to:
Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947

For IE also there is an object loop:

Code: Select all

q:: ;internet explorer - count tabs
WinGet, hWnd, ID, ahk_class IEFrame
vCount := 0
for oWin in ComObjCreate("Shell.Application").Windows
	if (hWnd = oWin.Hwnd)
		vCount++
MsgBox, % vCount
return
Potentially, enumerating the controls will reveal the answer:

Code: Select all

q:: ;list controls
WinGet, hWnd, ID, A
WinGet, vCtlList, ControlList, % "ahk_id " hWnd
Loop, Parse, vCtlList, `n
{
	vCtlClassNN := A_LoopField
	vOutput .= vCtlClassNN "`r`n"
}
Clipboard := vOutput
MsgBox, % "done"
return
E.g. for IE:

Code: Select all

q:: ;internet explorer - count tabs
WinGet, hWnd, ID, ahk_class IEFrame
Loop
{
	vCount := A_Index-1
	ControlGet, hCtl, Hwnd,, % "Internet Explorer_Server" A_Index, % "ahk_id " hWnd
	if !hCtl
		break
}
MsgBox, % vCount
return
Last edited by jeeswg on 05 Jun 2017, 10:53, edited 2 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
paik1002
Posts: 352
Joined: 28 Nov 2015, 02:45

Re: Count number of tabs in active window

05 Jun 2017, 10:39

jeeswg wrote:TCM_GETITEMCOUNT or the AccViewer/the Acc library are probably the way to go.

I plan to add some functions for IE to:
Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947

For IE also there is an object loop:

Code: Select all

q:: ;internet explorer - count tabs
WinGet, hWnd, ID, ahk_class IEFrame
vCount := 0
for oWin in ComObjCreate("Shell.Application").Windows
	if (hWnd = oWin.Hwnd)
		vCount++
MsgBox, % vCount
return
Potentially, enumerating the controls will reveal the answer:

Code: Select all

q:: ;list controls
WinGet, hWnd, ID, A
WinGet, vCtlList, ControlList, % "ahk_id " hWnd
Loop, Parse, vCtlList, `n
{
	vCtlClassNN := A_LoopField
	vOutput .= vCtlClassNN "`r`n"
}
Clipboard := vOutput
MsgBox, % "done"
return
E.g. for IE:

Code: Select all

q:: ;internet explorer - count tabs
WinGet, hWnd, ID, ahk_class IEFrame
Loop
{
	vCount := A_Index-1
	ControlGet, hCtl, Hwnd,, % "Internet Explorer_Server" A_Index, % "ahk_id " hWnd
	if !hCtl
		break
}
MsgBox, % vCount
return

Thank you for furnishing the sample scripts!
I think this will do just nicely, for meeting my objectives in a piecewise fashion.

Return to “Ask For Help”

Who is online

Users browsing this forum: Odlanir, vsub and 233 guests