Jump to content
Sign in to follow this  

Automating Scroll bars

Recommended Posts


I'm a newb to AutoIt and coding in general. I have been working with AutoIt for a few months now and have already had lots of success, but I've hit a wall.

A few years ago we contracted out to a group to automate a Windows app for us using QTP (Quick Test Professional)...the code sucks and I'm constantly having to restart the automation scripts.

I've been re-coding the QTP automation into AutoIt and am stuck when it comes to controlling a scroll bar. I can get the scroll bar to move but the actual window doesn't refresh. I have tried many different methods of moving the scroll bar (except for actually moving it with the mouse), but none refresh the window. I have also tried sending keyboard commands, Arrow-down, Page-down, etc., and refresh commands (_WinAPI) but those don't work either. In QTP, the scroll bar and window act normally with the command: "WinObject("AfxWnd42").VScroll micPageNext, 2", but I can't seem to find anything in AutoIt that acts similarily.

Thanks for any help!

(I apologize for the sloppyness of my code, but it's a result of trying lots of variations)


#include <GuiTab.au3>
#Include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <TreeviewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIListBox.au3>
#include <_XMLDomWrapper.au3>
#Include <GuiComboBoxEx.au3>
#Include <GuiScrollBars.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <ScrollBarConstants.au3>
#include <GuiEdit.au3>
#include <GuiStatusBar.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#Include <GuiScroll.au3>
#Include <WinAPI.au3>

AutoItSetOption("MustDeclareVars", 0)
Local $Max, $yPos, $Page, $Pos
WinActivate("Somnologica - [","")


Local $hWnd = ControlGetHandle("Somnologica - [","","[CLASS:AfxWnd42; INSTANCE:8]")
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)

$Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)

_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO, True)
;_GUIScrollBars_ScrollWindow($hWnd, 0, $Pos + $Page)
;Scrollbar_Scroll($hWnd, $SB_VERT, $Max)


;Local $hWnd2 = ControlGetHandle("Somnologica - [","","[CLASS:Afx:400000:0]")
Local $hWnd2 = WinGetHandle ("Somnologica - [","")
ConsoleWrite("hWnd2: " & $hWnd2 & @CRLF)

;Local $return = _WinAPI_UpdateWindow($hWnd2)
Local $return = _WinAPI_RedrawWindow($hWnd2,0,0,$RDW_ERASE)
ConsoleWrite("Update: " & $return & @CRLF)

MouseMove ((0.5*@DesktopWidth), (0.75*@DesktopHeight))
ConsoleWrite((0.5*@DesktopWidth) & " " & (0.75*@DesktopHeight) & @CRLF)

Share this post

Link to post
Share on other sites

As I see, it's not in any part child of your window so it's completely different process with different address space so passing your own pointer of structure to get or set data on that control probably is the root of the problem (correct me if I'm wrong).

You need to use VirtualAllocEx, WriteProcessMemory, ReadProcessMemory and the like to use inter-process pointers. Look at the function _GUICtrlListView_GetItemEx() for example for doing this. Usually this is done by the _GUI* functions but not in this case.

Share this post

Link to post
Share on other sites

One method I've used to send linescroll messages is to send this message:

GUICtrlSendMsg($hControlIDToLink,0x00B6,0,$iVerticalDelta); EM_LINESCROLL [SEND]

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
Sign in to follow this