Jump to content

Obtaining Min and Max values from ScrollBar


Recommended Posts

I've been attempting to retrieve Min-Max values from a scrollbarobject in another app. Using utilities such as WinCheat, I've been able to obtain that info by sending SBM_GETRANGE. Now I wish to do this using AutoIt.

Any scrollbar UDFs I've used appear to be specific to scrollbars created in AutoIt GUIs. I hope I'm wrong on this as it would be easier for me to use them than going the API route. Searching MSDN and Google Groups, I was able to cobble together the following code but it is not returning the max value as expected (e.g. it is always 0 ). What am I doing wrong here?

CONST $SIF_RANGE = 0x00000001
CONST $SB_VERT = 0x00000001

$hWnd = ControlGetHandle( "Application Under Test", "", 59920 )
$MIN = DllStructCreate( "int")
$MAX = DllStructCreate( "int")

DllCall( "user32.dll", "int", "GetScrollRange", "hwnd", $hWnd, "int", $SB_VERT, "ptr", DllStructGetPtr( $MIN ), "ptr", DllStructGetPtr( $MAX ))
ConsoleWrite( DllStructGetData( $MAX, 1 ) & @CRLF)

Here is the GetScrollRange Function from MSDN:

BOOL GetScrollRange(      
    HWND hWnd,
    int nBar,
    LPINT lpMinPos,
    LPINT lpMaxPos
);
Edited by zfisherdrums
Link to comment
Share on other sites

I've been attempting to retrieve Min-Max values from a scrollbarobject in another app. Using utilities such as WinCheat, I've been able to obtain that info by sending SBM_GETRANGE. Now I wish to do this using AutoIt.

Any scrollbar UDFs I've used appear to be specific to scrollbars created in AutoIt GUIs. I hope I'm wrong on this as it would be easier for me to use them than going the API route. Searching MSDN and Google Groups, I was able to cobble together the following code but it is not returning the max value as expected (e.g. it is always 0 ). What am I doing wrong here?

CONST $SIF_RANGE = 0x00000001
CONST $SB_VERT = 0x00000001

$hWnd = ControlGetHandle( "Application Under Test", "", 59920 )
$MIN = DllStructCreate( "int")
$MAX = DllStructCreate( "int")

DllCall( "user32.dll", "int", "GetScrollRange", "hwnd", $hWnd, "int", $SB_VERT, "ptr", DllStructGetPtr( $MIN ), "ptr", DllStructGetPtr( $MAX ))
ConsoleWrite( DllStructGetData( $MAX, 1 ) & @CRLF)

Here is the GetScrollRange Function from MSDN:

BOOL GetScrollRange(      
    HWND hWnd,
    int nBar,
    LPINT lpMinPos,
    LPINT lpMaxPos
);
Normally, you'd want to use GetScrollInfo for this. I've used this before and it works on both AutoIt and external controls. You just need to make sure you're passing the handle to the external control and not the handle to the external app window. Also, if the control is empty (i.e. has no text in it), the min/max values returned will always be 0. If the control has one line of text, then the min/max values will be 0/1 respectively. Here's an example using an AutoIt created control which can be adapted for external controls (you'll need at least beta 3.2.3.2 for the new structure format):

#include <GUIConstants.au3>

Global Const $SB_VERT   = 1
Global Const $SIF_RANGE = 0x0001

Global $hGUI, $iMemo, $hMemo, $tInfo, $aResult

$hGUI  = GUICreate("Scroll Bar Range", 400, 300)
$iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
$hMemo = GUICtrlGetHandle($iMemo)
GUISetState()

GUICtrlSetData($iMemo, "Line 1" & @CRLF, 1)
GUICtrlSetData($iMemo, "Line 2" & @CRLF, 1)

$tInfo = DllStructCreate("uint Size;uint Mask;int Min;int Max;uint Page;int Pos;int TrackPos")
$tInfo.Size = DllStructGetSize($tInfo)
$tInfo.Mask = $SIF_RANGE

$aResult = DllCall("User32.dll", "int", "GetScrollInfo", "hwnd", $hMemo, "int", $SB_VERT, "ptr", DllStructGetPtr($tInfo))
if $aResult[0] = 0 then
  ConsoleWrite("GetScrollInfo failed" & @CR)
else
  ConsoleWrite("Min : " & $tInfo.Min & @CR)
  ConsoleWrite("Max : " & $tInfo.Max & @CR)
endif

do
until GUIGetMsg() = $GUI_EVENT_CLOSE
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

PaulIA,

Thank you so much for your quick reply! I was able to validate the code you posted and was also able to validate against an instance of Notepad. Unfortunately, my problem persists with the original app. The script is coming back with "GetScrollInfo failed". Allow me to share some additional info that I initially left out for brevity's sake.

The scroll bar is in a control with the name "AfxWnd422". Does this mean it has something to do with MFC? Does this complicate the matter?

Here is your script - albeit modified for the app. Does anything stand out that might explain the complication?

#include <GUIConstants.au3>

Global Const $SB_VERT   = 1
Global Const $SIF_RANGE = 0x0001

Global $hMemo, $tInfo, $aResult

$hMemo = ControlGetHandle( "AUT", "", "AfxWnd422")
; also tried ---> $hMemo = ControlGetHandle( "AUT", "", "ScrollBar3")
$tInfo = DllStructCreate("uint Size;uint Mask;int Min;int Max;uint Page;int Pos;int TrackPos")
$tInfo.Size = DllStructGetSize($tInfo)
$tInfo.Mask = $SIF_RANGE

$aResult = DllCall("User32.dll", "int", "GetScrollInfo", "hwnd", $hMemo, "int", $SB_VERT, "ptr", DllStructGetPtr($tInfo))
if $aResult[0] = 0 then
  ConsoleWrite("GetScrollInfo failed" & @CR)
else
  ConsoleWrite("Min : " & $tInfo.Min & @CR)
  ConsoleWrite("Max : " & $tInfo.Max & @CR)
endif

edit: Not trying to intentionally bump, but just remembered that I did not indicate what the script responded with.

Edited by zfisherdrums
Link to comment
Share on other sites

  • 1 year later...

#include <GUIConstants.au3>

Global Const $SB_VERT   = 1
Global Const $SIF_RANGE = 0x0001

Global $hMemo, $tInfo, $aResult

$hMemo = ControlGetHandle( "AUT", "", "AfxWnd422")
; also tried ---> $hMemo = ControlGetHandle( "AUT", "", "ScrollBar3")
$tInfo = DllStructCreate("uint Size;uint Mask;int Min;int Max;uint Page;int Pos;int TrackPos")
$tInfo.Size = DllStructGetSize($tInfo)
$tInfo.Mask = $SIF_RANGE

$aResult = DllCall("User32.dll", "int", "GetScrollInfo", "hwnd", $hMemo, "int", $SB_VERT, "ptr", DllStructGetPtr($tInfo))
if $aResult[0] = 0 then
  ConsoleWrite("GetScrollInfo failed" & @CR)
else
  ConsoleWrite("Min : " & $tInfo.Min & @CR)
  ConsoleWrite("Max : " & $tInfo.Max & @CR)
endif

when i exec this script i got error at $tInfo.Size = DllStructGetSize($tInfo) --> Variable must be of type "Object"

help me how can i fix this error Plz !

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...