Jump to content

moving scrollbar


Recommended Posts

I'm sure this is easy but I can't seem to find anything that I can understand in the forum on this. Simply put I need a function that will scroll a window up and down or sideways. The function needs to allow me to tell it how much to scroll and in which direction. If there were a simple command such as:

ScrollWindow("up",2) where up is the direction I want to scroll and 2 is the distance in pixels I want the scroll bar to move

Unfortunately it seems I can't find a simple command like this but this is what I need. Can anyone help?

Link to comment
Share on other sites

#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>

Dim $hFile, $hEdit
Dim $sStr, $sFile
Dim $tSBI

$sStr = 'AutoIt_1-2-3' & @CRLF
$sFile = @ScriptDir & '\Test.txt'
$hFile = FileOpen($sFile, 2)

For $i = 1 To 10
    $sStr &= $sStr
Next

FileWrite($hFile, $sStr)
FileClose($hFile)
ShellExecute($sFile)
WinWaitActive('[CLASS:Notepad]')
$hEdit = ControlGetHandle('[CLASS:Notepad]', '', 'Edit1')
$tSBI = DllStructCreate($tagSCROLLINFO)
    DllStructSetData($tSBI, 'cbSize', DllStructGetSize($tSBI))
    DllStructSetData($tSBI, 'fMask', $SIF_ALL)

If _GUIScrollBars_GetScrollInfo($hEdit, $SB_VERT, $tSBI) Then
    Local $iMax = DllStructGetData($tSBI, 'nMax')   
    DllStructSetData($tSBI, 'nPos', Round($iMax*0.75))
    _GUIScrollBars_SetScrollInfo($hEdit, $SB_VERT, $tSBI)
Else
    ConsoleWrite('Error' & @LF)
EndIf

$tSBI = 0

Could be much simpler but demonstrating nothing...

Link to comment
Share on other sites

#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>

Dim $hFile, $hEdit
Dim $sStr, $sFile
Dim $tSBI

$sStr = 'AutoIt_1-2-3' & @CRLF
$sFile = @ScriptDir & '\Test.txt'
$hFile = FileOpen($sFile, 2)

For $i = 1 To 10
    $sStr &= $sStr
Next

FileWrite($hFile, $sStr)
FileClose($hFile)
ShellExecute($sFile)
WinWaitActive('[CLASS:Notepad]')
$hEdit = ControlGetHandle('[CLASS:Notepad]', '', 'Edit1')
$tSBI = DllStructCreate($tagSCROLLINFO)
    DllStructSetData($tSBI, 'cbSize', DllStructGetSize($tSBI))
    DllStructSetData($tSBI, 'fMask', $SIF_ALL)

If _GUIScrollBars_GetScrollInfo($hEdit, $SB_VERT, $tSBI) Then
    Local $iMax = DllStructGetData($tSBI, 'nMax')   
    DllStructSetData($tSBI, 'nPos', Round($iMax*0.75))
    _GUIScrollBars_SetScrollInfo($hEdit, $SB_VERT, $tSBI)
Else
    ConsoleWrite('Error' & @LF)
EndIf

$tSBI = 0

Could be much simpler but demonstrating nothing...

It took me a while to get to this. Sorry! It seems that the text itself does not actually scroll but only the scroll bar moves. Can this be modified so that the text scrolls just as if you were manually moving the scroll bar? You'll see what I mean if you use the following code, execute it, and then open a text file in notepad (have it ready to go as you can see I left just 5 seconds to test). Also I noticed that in other places such as the Autoit help file the scroll bar doesn't move at all.

#include <GUIScrollBars.au3>

#include <ScrollBarConstants.au3>

Sleep(5000); have a text file in notepad ready to switch to after running script

Dim $tSBI

$hEdit = ControlGetHandle('[Active]', '', 'Edit1')

$tSBI = DllStructCreate($tagSCROLLINFO)

DllStructSetData($tSBI, 'cbSize', DllStructGetSize($tSBI))

DllStructSetData($tSBI, 'fMask', $SIF_ALL)

If _GUIScrollBars_GetScrollInfo($hEdit, $SB_VERT, $tSBI) Then

Local $iMax = DllStructGetData($tSBI, 'nMax')

DllStructSetData($tSBI, 'nPos', Round($iMax*0.2))

_GUIScrollBars_SetScrollInfo($hEdit, $SB_VERT, $tSBI)

Else

ConsoleWrite('Error' & @LF)

EndIf

$tSBI = 0

Link to comment
Share on other sites

#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Sleep(5000); have a text file in notepad ready to switch to after running script

Dim $tSBI

WinWaitActive('[CLASS:Notepad]')
$hEdit = ControlGetHandle('[CLASS:Notepad]', '', 'Edit1')
$tSBI = DllStructCreate($tagSCROLLINFO)
DllStructSetData($tSBI, 'cbSize', DllStructGetSize($tSBI))
DllStructSetData($tSBI, 'fMask', $SIF_ALL)

If _GUIScrollBars_GetScrollInfo($hEdit, $SB_VERT, $tSBI) Then
Local $iMax = DllStructGetData($tSBI, 'nMax')
_SendMessage($hEdit, $WM_VSCROLL, _WinAPI_MakeDWord($SB_THUMBPOSITION, Round($iMax*0.2)), 0)
_GUIScrollBars_SetScrollInfo($hEdit, $SB_VERT, $tSBI)
Else
ConsoleWrite('Error' & @LF)
EndIf

$tSBI = 0

Link to comment
Share on other sites

#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Sleep(5000); have a text file in notepad ready to switch to after running script

Dim $tSBI

WinWaitActive('[CLASS:Notepad]')
$hEdit = ControlGetHandle('[CLASS:Notepad]', '', 'Edit1')
$tSBI = DllStructCreate($tagSCROLLINFO)
DllStructSetData($tSBI, 'cbSize', DllStructGetSize($tSBI))
DllStructSetData($tSBI, 'fMask', $SIF_ALL)

If _GUIScrollBars_GetScrollInfo($hEdit, $SB_VERT, $tSBI) Then
Local $iMax = DllStructGetData($tSBI, 'nMax')
_SendMessage($hEdit, $WM_VSCROLL, _WinAPI_MakeDWord($SB_THUMBPOSITION, Round($iMax*0.2)), 0)
_GUIScrollBars_SetScrollInfo($hEdit, $SB_VERT, $tSBI)
Else
ConsoleWrite('Error' & @LF)
EndIf

$tSBI = 0

I'm still running into the problem of this only working on notepad (I altered the script so it would work on any active window to test this). It does scroll now in notepad though (although the scroll bar doesn't move). What I'm looking for is a way to scroll ANY window from within a script. The scrolling should ideally not just include the contents of the window but the scroll button as well. Is there any way to do this with Autoit? Thanks for your help!

Link to comment
Share on other sites

The problem is if the window or control are not one Microsoft's predefined control, an owner-drawn control or processing scrolling using WM_VSCROLL then you won't be able to do this automation using the standard messages. You'll need to use WinSpector to see what messages is posted from or to the control or window and send this message. As for the scroll bar not being updated:

#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Dim $tSBI
Dim $sFile = @ScriptDir & '\Testttt.txt'
Dim $hFile
Dim $sStr = ''

For $i = 1 To 50
    $sStr &= $i & @CRLF
Next

$hFile = FileOpen($sFile, 2)
FileWrite($hFile, $sStr)
FileClose($hFile)

ShellExecute($sFile)
WinWaitActive('[CLASS:Notepad]')
$hEdit = ControlGetHandle('[CLASS:Notepad]', '', 'Edit1')
$tSBI = DllStructCreate($tagSCROLLINFO)
DllStructSetData($tSBI, 'cbSize', DllStructGetSize($tSBI))
DllStructSetData($tSBI, 'fMask', $SIF_ALL)

If _GUIScrollBars_GetScrollInfo($hEdit, $SB_VERT, $tSBI) Then
Local $iMax = DllStructGetData($tSBI, 'nMax')
_SendMessage($hEdit, $WM_VSCROLL, _WinAPI_MakeDWord($SB_THUMBPOSITION, Round($iMax*0.2)), 0)
DllStructSetData($tSBI, 'nPos', Round($iMax*0.2))
_GUIScrollBars_SetScrollInfo($hEdit, $SB_VERT, $tSBI)
Else
ConsoleWrite('Error' & @LF)
EndIf

$tSBI = 0oÝ÷ Ù±ßÛ+a{²Ê§yçm¢ÇÂÊ'¶º%¢¼"Ú0iËnjYrríj)춬rº%¶«mçºÇ¬zwbaɱ¨~ÞÅ©©ëh¶©j·§¶íç×(Úè¥Ú'¢ØbÞq«¬z+wöƬrº%¶«¡ûayçbµÊ'¶º%bjw!yÉ"¶X¤zØb±«­¢+Ø¥¹±Õ±Ðí
½¹ÍѹÑ̹ÔÌÐì(¥¹±Õ±Ðí]¥¹A$¹ÔÌÐì(¥¹±Õ±Ðí]¥¹½ÝÍ
½¹ÍѹÑ̹ÔÌÐì()¥´ÀÌØí¡¥Ðô
½¹Ñɽ±Ñ!¹± Ìäím
1MLé9½ÑÁtÌäì°ÌäìÌäì°Ìäí¥ÐÄÌäì¤)¥´ÀÌØí¥MÑå±ô}]¥¹A%}Ñ]¥¹½Ý1½¹ ÀÌØí¡¥Ð°ÀÌØí]1}MQe1¤()%   ¥Ñ¹ ÀÌØí¥MÑå±°ÀÌØí]M}YM
I=10¤Q¡¸(ìÙÉÑ¥°Íɽ±°¥ÌÁÉ͹Ð)¹%
Edited by Authenticity
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...