How Test Control Locates Controls Withouth Captions

ID Number: Q84834

1.00

WINDOWS

Summary:

TESTCTRL.DLL (Test Control) locates a control first by its caption,

and second by its specified class. It uses the following logic:

1. If a control does not have a caption, Test Control looks for a

STATIC control with a matching caption (for example,

WListExists("My ListBox")).

2. If a STATIC control with the specified caption is found,

Test Control will then look for the first non-STATIC control

following the STATIC control.

3. If it finds a non-STATIC control, it then compares its class to the

class it's looking for. (In the above example, it's looking for the

class to be "LISTBOX". If it finds the non-STATIC control class to

be "LISTBOX", then WListExists will return TRUE. If that non-STATIC

control is of another class, WListExists will return FALSE.)

4. In any case, if Test Control cannot find the control specified, it

will report the control as not found.

For Test Control to find captionless controls correctly, the tab order

of the dialog boxes must be correct in relation to the controls and

their 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 Test Control not finding

controls that are really there, or incorrectly identifying controls as

those of another class.

This information applies to Microsoft Test for Windows version 1.0.

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, command button, check box, or option

button). A non-captioned control does not have an integrated caption

(for example, list box, combo box, or scroll bar). However, all

controls have a control class (for example, EDIT and LISTBOX).

If you have a window with a list box and other controls on it, you

can run the following code in Microsoft Test:

'$Define TESTCTRL

'$Include: 'MSTEST.INC'

If WListExists("&File:") Then

Print "List Box found"

Else

Print "List Box not found"

End If

If it resulted in "List Box not found" when the code was run, then

either:

- Test Control could not find a STATIC control with the caption

"&File:"

-or-

- Test Control did find a STATIC control with a caption of "&File:",

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 "SetClass" Test Control routine so that the custom class

will be recognized by the appropriate Test Control routine. Using the

above example, and assuming that your custom list box class was

"MYLISTBOX," you could place the following code before the call to

WListExists to allow Test Control to locate your custom list box:

WListSetClass "MYLISTBOX"

If you are having problems locating controls in your application with

Test Control 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 "" (blank) for the

name argument (for example, WListExists("")).

Additional reference words: 1.00