Detect if classNN is scrollable

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Detect if classNN is scrollable

20 May 2017, 14:40

How do I detect if a certain classNN(e.g. WinClassNN), over which the mouse is currently hovering is vertically scrollable?
The window having WinClassNN is not necessarily active.

A sample script illustrating it would be helpful.

Code: Select all

^+!F12::
{
	MouseGetPos,,,, WinClassNN	
	
	; Detect if WinClassNN is vertically scrollable
	
	return
}
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Re: Detect if classNN is scrollable

20 May 2017, 15:10

Sorry, but I have no idea how those links you provided can help detect scrollability of a certain classNN, e.g. Internet Explorer_Server1, DirectUIHWND3, SysTreeView321, _WwG1, etc.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Detect if classNN is scrollable

20 May 2017, 15:22

If you try AccViewer on Notepad for example, with no text v. enough text to need the vertical scrollbar, the state is either 'unavailable' or 'normal'.

You can use WBGet to get access to the Internet Explorer_Server control and query scroll information which might give you what you need.

[I'll be able to post some code in maybe half-an-hour.] [EDIT: A few hours later ...]

Code: Select all

e:: ;check for WS_VSCROLL window style
WinGet, hWnd, ID, A
ControlGetFocus, vCtlClassNN, % "ahk_id " hWnd
ControlGet, vCtlStyle, Style,, % vCtlClassNN, % "ahk_id " hWnd
MsgBox, % vCtlClassNN "`r`n" "has WS_VSCROLL? " !!(vCtlStyle & 0x200000) ;WS_VSCROLL := 0x200000
return

q:: ;Notepad - get vertical scrollbar state
ControlGet, hCtl, Hwnd,, Edit1, ahk_class Notepad
oAcc := Acc_Get("Object", "5", 0, "ahk_id " hCtl)
vChildId := 0
vAccStateNum := oAcc.accState(vChildId)
vAccStateNum := Format("0x{:X}", vAccStateNum)
vAccStateText := Acc_GetStateText(oAcc.accState(vChildId))
MsgBox, % vAccStateNum " " vAccStateText
oAcc := ""
return

;w:: ;Internet Explorer - get scroll height
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
vScrollHeight1 := oWB.document.body.scrollHeight
vScrollHeight2 := oWB.document.documentElement.scrollHeight
;vScrollTop := oWB.document.documentElement.scrollTop
MsgBox, % vScrollHeight1 " " vScrollHeight2
return
Note: there is probably a better method for Internet Explorer, this tries to get the amount of the document visible, versus the amount in total, however, there seems to be a rounding issue, so it's not reliable.
Last edited by jeeswg on 20 May 2017, 19:01, edited 6 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
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Detect if classNN is scrollable

20 May 2017, 15:22

paik1002 wrote:Sorry, but I have no idea how those links you provided can help detect scrollability of a certain classNN, e.g. Internet Explorer_Server1, DirectUIHWND3, SysTreeView321, _WwG1, etc.

Code: Select all

Gui, 1:+hwndID1
Gui, 1:Add, Tab, +0x200000, General|View|Appearance|Settings
Gui, 1:Add, Tab, -0x200000, General|View|Appearance|Settings
Gui, 1:Show, w400 h400
return

!i::
Loop, 2
{
ControlGet, controlStyle%a_index%, Style,, SysTabControl32%a_index%, % "ahk_id " . ID1
MsgBox % "Tab " . a_index . "is " . ((SuBStr(controlStyle%a_index%, -5, 1) == 2) ? "" : "not") . " scrollable"

}
return
my scripts
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Re: Detect if classNN is scrollable

21 May 2017, 00:52

jeeswg wrote:If you try AccViewer on Notepad for example, with no text v. enough text to need the vertical scrollbar, the state is either 'unavailable' or 'normal'.

You can use WBGet to get access to the Internet Explorer_Server control and query scroll information which might give you what you need.

[I'll be able to post some code in maybe half-an-hour.] [EDIT: A few hours later ...]

Code: Select all

e:: ;check for WS_VSCROLL window style
WinGet, hWnd, ID, A
ControlGetFocus, vCtlClassNN, % "ahk_id " hWnd
ControlGet, vCtlStyle, Style,, % vCtlClassNN, % "ahk_id " hWnd
MsgBox, % vCtlClassNN "`r`n" "has WS_VSCROLL? " !!(vCtlStyle & 0x200000) ;WS_VSCROLL := 0x200000
return

q:: ;Notepad - get vertical scrollbar state
ControlGet, hCtl, Hwnd,, Edit1, ahk_class Notepad
oAcc := Acc_Get("Object", "5", 0, "ahk_id " hCtl)
vChildId := 0
vAccStateNum := oAcc.accState(vChildId)
vAccStateNum := Format("0x{:X}", vAccStateNum)
vAccStateText := Acc_GetStateText(oAcc.accState(vChildId))
MsgBox, % vAccStateNum " " vAccStateText
oAcc := ""
return

;w:: ;Internet Explorer - get scroll height
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
vScrollHeight1 := oWB.document.body.scrollHeight
vScrollHeight2 := oWB.document.documentElement.scrollHeight
;vScrollTop := oWB.document.documentElement.scrollTop
MsgBox, % vScrollHeight1 " " vScrollHeight2
return
Note: there is probably a better method for Internet Explorer, this tries to get the amount of the document visible, versus the amount in total, however, there seems to be a rounding issue, so it's not reliable.

Thank you for the help.
I guess, there is no general solution that can be applied to all applications.

On the otherhand, is there a way to detect the presence of a scrollbar for a certain ClassNN?

Code: Select all

^+!F12::
{
	MouseGetPos,,,, WinClassNN	

	; Detect if WinClassNN is vertically scrollable. For example,
	if WinClassNN and WS_VSCROLL		; Check if a scrollbar exists in WinClassNN (this does not work!)
	{
		msgbox scrollbar exists for %WinClassNN%
	}
	return
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 192 guests