The information in this article applies to:
- Microsoft Visual Test for Windows 95 and Windows NT, version 4.0
- Microsoft Test for Windows, version 3.0a
SUMMARY
In Visual Test, you can create and use resources in TestBasic scripts, so
you can customize everything from pointers to dialog boxes. The abilty to
use resources provides you with many of the same tools used in other
Windows-based applications, so you can develop more robust Test scripts.
This article gives you a general overview of the steps required to create
and use resources in TestBasic code. Specifically, a menu and dialog box
resource will be created by using the Resource Editor and then used in
TestBasic code.
MORE INFORMATION
Steps to Create Menu and Dialog Resources and Use Them in TestBasic Code
- On the Insert Menu, click Resource.
- In the Insert Resource dialog box, select Menu, and click OK. A menu
resource identified by IDR_MENU1 is created by default, and the menu
region will be highlighted.
- Click the right mouse button (right-click) the highlighted menu region,
and click Properties. Type File as the caption, and close the Properties
tab. By default, the menu item will be highlighted.
- Right-click the highlighted menu item, and select Properties. Type
IDR_LIST1 as the ID number and List as the caption. Close the properties
tab.
- On the Insert menu, click Resource. Select Dialog, and click OK. A
Dialog resource identified by IDD_DIALOG1 is created by default.
- Right-click the Dialog box, and then click Properties. Select IDR_MENU1
from the Menu: list. This will integrate the menu resource with the
dialog resource.
- Place a list box and a command button (Button1) on the dialog box
- Save the resource file as TestRes1.Vtr, and close the file and
associated windows.
- Insert the following code into a new window:
'$include 'declares.inc'
'identify the resource file
'$RESOURCE 'TESTRES1.VTR'
'declare the dialog type
dim Dlg1 as IDD_Dialog1
'create pointer to the dialog procedure
Dlg1.Proc = varptr(MyDlgProc)
'display and process dialog
if Dialog(Dlg1, NULL) = IDOK then
end
end if
function MyDlgProc(hwnd&, msg&, wParam&, lParam&) as long
static hwndLB as long
Dim buffer as string
MyDlgProc = TRUE
select case msg
case WM_INITDIALOG
hwndLB = GetDlgItem(hwnd, IDC_LIST1)
'initialize by populating the single select listbox
ret = SendMessage(hwndLB, LB_ADDSTRING, 0,"list1")
ret = SendMessage(hwndLB, LB_ADDSTRING, 0,"list2")
case WM_COMMAND
select case wParam
case IDOK, IDCANCEL 'for OK or Cancel button simply end
EndDialog hwnd, IDOK
case IDC_BUTTON1 'process command button - Button1
buffer = Space$(10)
'obtain and print the selected listbox item
item = SendMessage(hwndLB, LB_GETCURSEL, 0, 0)
SendMessage hwndLB, LB_GETTEXT, item, buffer
Print buffer
end select
case WM_MENUSELECT
select case LOWORD(wParam)
case IDR_LIST1 'process our specific menu item - List
buffer = Space$(10)
'obtain and print the selected listbox item
item = SendMessage(hwndLB, LB_GETCURSEL, 0, 0)
SendMessage(hwndLB, LB_GETTEXT, item, buffer)
Print buffer
end select
case else
MyDlgProc = FALSE
end select
end function
- Run the script. Select the first item (list1) and click Button1.
You will see "list1" is output to the Viewport. Next, select the second
item (list2), and on the File menu, click List to see "list2" printed
to the Viewport. Click OK to end the program.
This sample provides an overview demonstrating how to create and use
resources. The TestBasic code itself only provides a framework for
processing Windows messages generated from the dialog box. In this case, a
button and single select list box were used in the dialog box, but Visual
Test can use many different controls - such as the TreeView control, one of
the new Windows common controls. You can investigate further uses of
resources by referring to "Using Resources in Test Language Files" in the
Programmer's Guide. Additional information can be found by performing
searches in the Help menu for a specific type of resource.
REFERENCES
Microsoft Systems Journal, 1994 Volume 9, July 1994 Number 7 - Cleverly
Coding with Chicago's Gadgets, Part I: Image Lists and TreeViews.
|