Microsoft KB Archive/156763

= Microsoft Knowledge Base =

How To Manipulate the ScrollBars on a Window
Last reviewed: January 10, 1997

Article ID: Q156763

The information in this article applies to:


 * Microsoft Visual Test for Windows, 32-bit only, version 4.0

SUMMARY
A window can contain either "Window ScrollBars" or "ScrollBar Controls." Visual Test provides the "WScrollBar..." functions in order to manipulate the "ScrollBar Controls." You can use the Windows API Functions to manipulate Window ScrollBars. You can use the Winfo Utility to distinguish between the two types of ScrollBars.

Scrollbar Controls
You will be able to select (highlight) these controls using the Winfo Utility. Useful information such as the ordinal value can be retrieved by Winfo. Once retrieved, these values can be used in the functions provided by Visual Test to manipulate the Scrollbar Controls. A good example is the use of the ordinal value retrieved by Winfo in the WScrollBar... Functions like WScrollSetPos:

WScrollSetPos ( "@1", 100) The Write program provided by Windows NT 3.51 is an example of an application that uses ScrollBar Controls.

Window Scrollbars
Another type of ScrollBar is the Window ScrollBar that is generated from setting a style within a newly-created window to enable it to contain a scrollbar.

Window ScrollBars are not stand-alone controls. Rather, they are physically part of the window. Because they are not individual controls, you will not be able to use the Visual Test WScrollBar... Functions to manipulate them. Window Scrollbars cannot be selected using the Winfo Utility.

The Notepad program provided by Windows 95 is an example of an application that uses Window ScrollBars.

To manipulate Window Scrollbars directly from Visual Test, you must use Windows API functions to interact with the Window ScrollBars. This article shows you how to do this.

Using Windows API's to Manipulate Scrollbars
The following steps detail the process of creating a Test language script that will manipulate scrollbars within Notepad. This example will start the Windows Notepad (NOTEPAD.EXE) application, load a Text file, and scroll halfway down the document:

 Start Visual Test, and then create a new script(.mst) file.  Type the following text into the script file you created in step 1: '$include 'declares.inc'

Dim timeout as long Dim hWpad as long ,hWedit as long

Dim FileName as string Dim WindowsPath as string Dim T as string Dim currentWindow as long Dim xcord as long, ycord as long

Timeout = 5

'You are trying to open the Readme.txt file in  'the windows95 directory. You need to change the 'file name if this file does not exist on your system.

WindowsPath = space$(200) Getwindowsdirectory(WindowsPath ,len(WindowsPath)) Filename = Trim(WindowsPath )+"\Readme.txt"

T = "Starting NotePad" StatusBox T, 1, 1,300,30,true,, "MS Sans Serif", 12, 900

Chdir  WindowsPath Run "NotePad.exe", Nowait

T = "Opening a Text File" StatusBox T, 1, 1,300,30,true,, "MS Sans Serif", 12, 900 

CurrentWindow = WFndWndC("Notepad", "Notepad", FW_FOCUS OR FW_PART,Timeout)

WMenuSelect("&File\&Open...") CurrentWindow = WFndWndC("Open", "#32770", FW_FOCUS OR FW_PART, Timeout)

sleep 3 'Setting the file name WEditsettext("File Name:",FileName) WButtonclick("Open")

hWPad = WFndWndC("Notepad", "Notepad",FW_PART or FW_FOCUS, Timeout)

hWedit = WFndWndC(_ord(1) ,"edit" ,FW_PART or FW_FOCUS ,timeout)

'Get the minimum/maximum range value that you can set to  'scroll the window GetScrollRange hWedit, SB_VERT ,Varptr(xcord) , Varptr(ycord)

' You can set some valid position value ' You are using half of the Maximum scroll range

lpvalue =mklng(SB_THUMBPOSITION,Ycord\2)

T = "Note that Notepad displays the top Page" StatusBox T, 1, 1,300,30,true,, "MS Sans Serif", 12, 900 sleep 3 'This sends a message to the parent window of the scrollbar

Ret = SendMessage(hwedit ,WM_VSCROLL,lpvalue ,NULL)

T = "Check to see if the Page in Notepad is Scrolled down"

StatusBox T, 1, 1,300,30,true,, "MS Sans Serif", 12, 900 sleep 3

T = "Closing Notepad" StatusBox T, 1, 1,300,30,true,, "MS Sans Serif", 12, 900

sleep 2 StatusBox close 'Closing Notepad and ending the Script CurrentWindow = WFndWndC("Notepad", "Notepad", FINDWINDOWFLAGS, Timeout) WMenuSelect("&File\Exit")

End Note that you are trying to open the Readme.txt file in the \Windows95\ directory. You need to change the filename if this file does not exist on your system.

Run the script and you will see a Status Box that displays information on what the program is doing.

REFEENCES
The sample code listed above uses the following Win32 API functions:

GetWindowsDirectory, SendMessage. For more information concerning these functions, please refer to the Win32 SDK Help files.

For more information on using the Winfo Utility, please refer to the Visual Test Online Help under:

Visual Test 4.0 Books Online \ Utilities User's Guide \ Window Information Utility