Jump to content

Any way to detect if window has scrollbar?


qwert
 Share

Recommended Posts

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

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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 (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

_GUIScrollBars_GetScrollInfo and other functions wont work with a Firefox window.  

Maybe IUIAutomation will be able to give you the info : https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...