qwert

Any way to detect if window has scrollbar?

9 posts in this topic

Is there a way to determine if a window has a scrollbar displayed?  I happen to be working with a browser window, but the question applies to windows, in general.

I tried the window info tool, but the parameters are the same with or without a scrollbar.  Both IE.3 and FF.au3 have many functions, but I couldn't spot anything related to scrollbars.  _IEPropertyGet, for example, can read many characteristics, but, apparently, nothing about the scrollbar.

Thanks in advance for any help.

 

Window Params.png

Share this post


Link to post
Share on other sites



#3 ·  Posted

Quote

$hWnd parameter must be the handle to the scroll bar control

Thanks for the response.

The problem is somewhat of a chicken and egg problem.  It's an external window and I'm trying to determine whether it has a scrollbar, or not.   Every function in the ScrollBars UDF appears to require the handle to the bar, which may not exist.

Do you know of a GetScrollBarHandle function?

 

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

I read it that the function needs a handle to the Control which might have a bar. Or am I wrong :huh:


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Maybe I read too much into the "must".  So it's possible the following will return True if the window has a scroll bar?

_GUIScrollBars_GetScrollInfo ( $hWnd, $SB_VERT, $tSCROLLINFO )

I will test that at my next opportunity.

Thanks.

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Can you try this code ?
It lists all controls in the specified window an uses _GUIScrollBars_GetScrollInfo for each control. It works for me with notepad, but not tested with anoter app.

#include <GuiScrollBars.au3>


If _WinDetectScrollbar("[Class:Notepad]") Then MsgBox(0, "", "The specified window has a scrollbar")


Func _WinDetectScrollbar($sTitle, $sText = "")
    Local $iCount, $iInstance, $hControl
    Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)

    Local $sClassList = WinGetClassList($sTitle, $sText)
    If $sClassList = "" Then Return 0

    Local $aClasses = StringRegExp($sClassList, "(?m)(^\N+$)(?!(?:\R(?1))*\R\1)", 3)

    For $i = 0 To UBound($aClasses) - 1
        StringRegExpReplace($sClassList, "\Q" & $aClasses[$i] & "\E\R", "")
        $iCount = @extended

        For $iInstance = 1 To $iCount
            $hControl = ControlGetHandle($sTitle, $sText, "[CLASS:" & $aClasses[$i] & "; INSTANCE:" & $iInstance& "]")

            DllStructSetData($tSCROLLINFO, "cbSize", DllStructGetSize($tSCROLLINFO))
            DllStructSetData($tSCROLLINFO, "fMask", $SIF_ALL)
            _GUIScrollBars_GetScrollInfo($hControl, $SB_HORZ, $tSCROLLINFO)
            If DllStructGetData($tSCROLLINFO, "nMax") >= DllStructGetData($tSCROLLINFO, "nPage") Then Return 1

            _GUIScrollBars_GetScrollInfo($hControl, $SB_VERT, $tSCROLLINFO)
            If DllStructGetData($tSCROLLINFO, "nMax") >= DllStructGetData($tSCROLLINFO, "nPage") Then Return 1
        Next
    Next
    Return 0
EndFunc

 

Edited by jguinch

Share this post


Link to post
Share on other sites

#7 ·  Posted

Quote

I happen to be working with a browser window

@jguinch: thanks for your script.  I did try it for notepad and it worked.  But when I pointed it to Class:MozillaWindowClass, it did not see the scrollbar. 

There may be complicating factors, like the fact that it's a tabbed browser window.  But the AutoIt Window Info tool always shows MozillaWindowClass, which, I assume, represents the open tab.

Do you have any suggestions?

 

Window Class.PNG

Share this post


Link to post
Share on other sites

#9 ·  Posted

Quote

wont work with a Firefox window

Well, that's interesting ... and disconcerting.  How is a window not a window?  But I'll accept that the scroll bar GUI functions won't work.

On first glance, IUIAutomation looks, shall I say, rather imposing.  At the moment, I don't have time to delve into a whole new realm.  So, for now, I guess I'll shelve my idea.

Thanks for looking at this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now