Working With Owner-Drawn ToolBars in Desktop Windows Applications

Applies to TestComplete 15.63, last modified on April 10, 2024

In order for TestComplete to work with individual toolbar buttons in scripts or keyword tests, it needs a way to identify and specify them. For this purpose, TestComplete uses either item captions, indexes (position within the toolbar) or IDs. Captions are more usually preferable than indexes, because they make tests more readable and stable, whereas indexes are less easy to understand and, moreover, they may change during the run. IDs also provide a stable way to identify toolbar buttons, but they are less easy to understand than indexes.

Standard Win32 controls are drawn by the operation system itself. However, Windows also lets applications handle drawing their controls, including toolbars, in a custom way. The controls drawn by the application are called owner-drawn. In general, owner-drawn controls may have no labels and their contents can be arbitrary. To learn whether your tested application owner draws its controls, ask the tested application developers.

If the toolbar is owner-drawn, TestComplete identifies its buttons using IDs. This means that TestComplete records actions with owner-drawn toolbars using button IDs. Since button IDs are constant, their usage ensures the scripts and keyword tests stability. When writing scripts for testing owner-drawn toolbars manually, you should also specify buttons by IDs (see Addressing Toolbar Buttons in Desktop Windows Applications). For example:

w.Window("MyCustomToolbarClass", "*").ClickItem(3802)

Tip: To make the test more readable, you can create special constants that will hold the button IDs and use these constants rather than the corresponding numeric values in the property and method calls:

JavaScript, JScript

var btnNew = 3802;
w.Window("MyCustomToolbarClass", "*").ClickItem(btnNew);


btnNew = 3802
w.Window("MyCustomToolbarClass", "*").ClickItem(btnNew)


Const btnNew = 3802
w.Window("MyCustomToolbarClass", "*").ClickItem(btnNew)


const btnNew = 3802;
  w.Window('MyCustomToolbarClass', '*').ClickItem(btnNew);

C++Script, C#Script

var btnNew = 3802;
w["Window"]("MyCustomToolbarClass", "*")["ClickItem"](btnNew);

This approach also makes it easier to update the test if button IDs in the tested application change in the next application version.

To specify items of owner-drawn toolbars by text, try using the appropriate approaches described in the Object Identification section. For other tips on dealing with non-standard controls, see Ways to Interact With Application Objects.

See Also

Working With Toolbars in Desktop Windows Applications
Testing Owner-Drawn Controls
Working With Third-Party Toolbars in Desktop Windows Applications
Addressing Toolbar Buttons in Desktop Windows Applications

Highlight search results