Microsoft Knowledge Base

How to Use Visual Test Version 4.0 with Custom Controls

Last reviewed: July 25, 1996
Article ID: Q135767
The information in this article applies to:
  • Microsoft Test for Windows 95, version 3.0a
  • Microsoft Visual Test for Windows 95, version 4.0

SUMMARY

Visual Test offers many high-level functions that make it easy to manipulate, control, retrieve data from, and send data to the standard Windows-based controls. To make Visual Test a robust testing platform, each of the control functions verify that the window they will act on has a class name that matches the control type specified. (See the "Class Names Visual Test Recognizes" section of this article for more information.) If the targeted window has the wrong class name, the control function generates a run-time error indicating that the control is not found.

Many custom controls are created to extend the functionality of a standard Windows-based control. These custom controls exhibit features very similar to the standard controls that they enhance and, in most cases, can be used by Visual Test as if they are the standard control. However, a common technique used to enhance a standard control, called superclassing, changes the window's class name, thus causing Visual Test to fail to recognize the control as handling standard Windows-based control properties.

MORE INFORMATION

Superclassing is a technique that allows an application to create a new window class with the basic functionality of the existing class plus enhancements provided by the application. A superclass is based on an existing window class called the base class. Frequently, the base class is a system global window class such as an edit control, but it can be any window class.

Once a window is created from the base class and information about the window's style is obtained, the window is destroyed. Then a new window class is registered by using the information obtained from the base class with some slight modifications to that information. The superclassed custom control is then created using the attributes of the newly created superclass.

For more information on the implementing a superclass, please see the Win32 Software Development Kit (SDK) by drilling down the following hierarchy:

Overviews

   Window Management
      Window Procedures
         About Window Procedures
            Window Procedure Superclassing

Class Names Visual Test Recognizes

The following table outlines the class names that Visual Test recognizes as being standard Windows-based controls.

Control Type       Recognized Class Names
Check Box          Button
                   ThunderCheckBox
Combo Box          ComboBox
                   ThunderComboBox
Command Button     Button
                   ThunderCommandButton
Header             SysHeader32
Label              Static
                   ThunderLabel
                   MT_Sb_Field
List Box           ListBox
                   ThunderListBox
List View          SysListView32
Option Button      Button
                   ThunderOptionButton
Progress           msctls_progress32
                   msctls_progress
Slider             msctls_trackbar32
Spin               msctls_updown32
                   msctls_updown
Status Bar         msctls_statusbar32
Tab                SysTabControl32
Text Box           Edit
                   RBEDIT
                   RICHEDIT
                   ThunderTextBox
Tool Bar           ToolbarWindow32
Tool Tips          tooltips_class32
                   tooltips_class
                   MT_Popup_Help
Tree View          SysTreeView32

How to Change Recognized Class Names

Most families of control functions offer a W*SetClass function, the '*' represents the family of control functions that SetClass will act upon. The W*SetClass takes one string argument, which represents the new class(es) that will be recognized by Visual Test as being a particular Windows control.

' The following line makes Visual Test
' recognize only 'MyEdit' as being an edit control:
WEditSetClass "MyEdit"

' Note: to make Visual Test recognize more than
' one class name use a backslash (\) to delimit
' the class names:
WEditSetClass "MyEdit\edit"

Please see the Visual Test Help menu for further details about W*SetClass.

Using WInfo to Determine a Window's Class Name

On the Test menu, click WInfo. The Window Information dialog box is displayed. Drag the target to the window for which you need information. The class name of the window will appear in the Class Name edit control.

Step-by-Step Demonstration of W*SETCLASS

  1. Copy the following code to a new script window under Visual Test:

       '$Include 'Declares'
    
       ' Automate the Currency application located in the samples directory.
       ' The Run statement assumes that Visual Test is installed in the
       ' default directory.
       Run "\MSDEV\Samples\VTest40\Currency\Currency.exe", NoWait
       WFndWnd "Currency", FW_PART or FW_FOCUS
    
       ' Click the button that has the arrow on it.
       Pause "The arrow button will be clicked. This will cause the arrow " + _
    
             "to reverse its direction." + Chr$(13) + Chr$(10) + _
             "Click OK to continue."
       ' Its ID # is &h000003FE.
       WButtonClick _id(&h000003FE)
       Pause "Click OK to quit demonstration."
    
    

  2. Run the script. Note that this code causes a run-time error:

          Button "#1220" does not exist....Error code: 125.
    

  3. On the Test menu, click WInfo. Drag the target to the command button that has an arrow on it. The Class Name edit control says ArrowButton.

  4. Modify the original code to read as follows:

       '$Include 'Declares'
    
       ' Automate the Currency application located in the samples directory.
       ' The Run statement assumes that Visual Test is installed in the
       ' default directory.
       Run "\MSDEV\Samples\VTest40\Currency\Currency.exe", NoWait
       WFndWnd "Currency", FW_PART or FW_FOCUS
    
       ' Before changing a recognized class name, it is a good idea
       ' to save the original so it can be restored.
       Dim strOriginalClassName As String
       strOriginalClassName = ButtonGetClass()
       ' Change the recognized class name.
       WButtonSetClass "ArrowButton"
       ' Click the button that has the arrow on it.
       Pause "The arrow button will be clicked. This will cause the arrow " + _
             "to reverse its direction." + Chr$(13) + Chr$(10) + _
             "Click OK to continue."
       ' Its ID # is &h000003FE.
       WButtonClick _id(&h000003FE)
       Pause "Click OK to quit demonstration."
       ' Restore the original recognized class name.
       WButtonSetClass strOriginalClassName
       WMenuSelect "File\Exit"
    
    

  5. Run the script. Note that the error message does not appear, and the button has been clicked.


Additional reference words: 4.00 Win32
KBCategory: kbprg kbcode kbtshoot kbwebcontent
KBSubCategory: MSTest


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 25, 1996
©1997 Microsoft Corporation. All rights reserved. Legal Notices.