Microsoft KB Archive/84834

= Microsoft Knowledge Base =

How Test Control Locates Controls Without Captions
Last reviewed: October 19, 1994

Article ID: Q84834

The information in this article applies to:


 * Microsoft Test for Windows, versions 1.0 and 2.0

SUMMARY
The routines in TESTCTRL.DLL locate a control first by its 'name', and second by its class. TestCtrl uses the following logic to locate a control:


 * 1) If a control does not have a caption, TestCtrl looks for a STATIC text control with a matching caption the request 'name'. A captionless control, such as a list box, is often preceeded by some text describing the control's purpose. This text is usually contained in a control of class STATIC. An example might be a list box proceeded by the static text &quot;Users:&quot; in which case a WListExists(&quot;Users:&quot;) could be used to verify if the list box exists.
 * 2) If a STATIC control with the specified caption is found, TestCtrl looks for the first non-STATIC control following the STATIC control in the tab order.
 * 3) If a non-STATIC control is found, TestCtrl then compares the control's class to the class TestCtrl is looking for. (In the WListExists example above, TestCtrl is looking for the class to &quot;LISTBOX&quot; (the default class for a Windows list box control). If TestCtrl finds the non-STATIC control class to be &quot;LISTBOX&quot;, then WListExists will return TRUE. If that non-STATIC control is of some other class, WListExists will return FALSE.)
 * 4) If any of the above steps fail, TestCtrl cannot find the control.

For TestCtrl to find captionless controls correctly, the tab order of the window or dialog box containing the control(s) must be correct in relation to the controls and their associated STATIC labels. (In other words, non-STATIC controls should follow their STATIC labels in the tab order.) If the control order is not set up correctly, you may have problems with TestCtrl not finding controls that are really there.

MORE INFORMATION
For the following example, controls can be separated into two groups: captioned and non-captioned. A captioned control has an integrated text caption (for example, a push button, check box, or option button). A non-captioned control does not have an integrated caption (for example, a list box, combo box, or edit control). All controls have a control class (for example, EDIT and LISTBOX) however.

If, for example, you have a window with a STATIC label &quot;&File:&quot; on it, and immediately following the label in the tab order is a list box, the following code will test for that list box's existance.:

' $Define TESTCTRL ' $Include: 'MSTEST.INC'

If WListExists(&quot;&File:&quot;) Then Print &quot;List Box found&quot; Else Print &quot;List Box not found&quot; End If If it resulted in &quot;List Box not found&quot; when the code was run, then either:

 TestCtrl could not find a STATIC control with the caption &quot;&File:&quot; -or- TestCtrl did find a STATIC control with a caption of &quot;&File:&quot;, but the first non-STATIC control following it was not a list box (that is, not of class LISTBOX).

If you are using a custom list box control (with a class name other then the standard Windows list box, LISTBOX), you can use the appropriate &quot;SetClass&quot; TestCtrl routine so that the custom class will be recognized by the appropriate TestCtrl routine. Using the above example, and assuming that your custom list box class was &quot;MYLISTBOX,&quot; you could place the following code before the call to WListExists so that TestCtrl can locate your custom list box:

WListSetClass &quot;MYLISTBOX&quot; If you are having problems locating controls in your application with TestCtrl routines, there are two ways to change the behavior:


 * Make sure the target non-STATIC control follows its associated STATIC label in the tab order. For applications created with the Windows Software Development Kit (SDK), this means the controls should be created one after the other (or they should be listed sequentially in the resource script file).
 * Set focus to the captionless control, then use &quot;&quot; (blank) for the name argument (for example, WListExists(&quot;&quot;)).
 * If you are using Microsoft Test version 2.0, you can identify a control by its ordinal position by specifying the name &quot;@#&quot;, where &quot;#&quot; is the ordinal postion of the control you what to work with. If you wanted to check for the existance of the second edit control in the tab order, you could use WEditExists(&quot;@2&quot;), for example. This feature is not supported in Microsoft Test 1.0.