Determining Header Items' Bounds in Desktop Windows Applications

Applies to TestComplete 15.47, last modified on January 20, 2023

While testing header controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

You may need to determine the bounds of header items, for example, if you need to click on a certain item, or change an item’s width. To obtain information about items’ dimensions, you can use the wItemBounds property of the Win32Header object, which is associated with all header controls listed in the Object Mapping project’s options list.

The wItemBounds property returns the Bounds object that provides information about the specified header item’s dimensions. You can obtain this information using the following properties:

  • Height - Returns the height of an item’s bounding rectangle.
  • Width - Returns the width of an item’s bounding rectangle.
  • Left - Specifies the horizontal coordinate of the upper-left corner of an item’s bounding rectangle.
  • Right- Returns the horizontal coordinate of the lower-right corner of an item’s bounding rectangle.
  • Top - Returns the vertical coordinate of the upper-left corner of an item’s bounding rectangle.
  • Bottom - Returns the vertical coordinate of the lower-right corner of an item’s bounding rectangle.

The following sample code posts information about header items’ width to the test log:

JavaScript, JScript

function Main()
{
  var p, w, i, Header, ItemNumber, ItemBounds;

  // Obtain the Explorer process, window and the header control
  WshShell.Run("explorer.exe c:", SW_NORMAL);
  p = Sys.Process("Explorer")
  w = p.Window("CabinetWClass", "SYSTEM (C:)", 1).Window("SHELLDLL_DefView", "", 1).Window("DUIViewWndClassName", "", 1).Window("DirectUIHWND", "", 1).Window("CtrlNotifySink", "", 1).Window("SysListView32", "FolderView", 1)
  Header = w.Window("SysHeader32", "", 1)
  
  // Post the items' width to the test log
  ItemNumber = Header.wItemCount
  for (i = 0; i<ItemNumber; i++)
  {
    ItemBounds = Header.wItemBounds(i);
    Log.Message(Header.wItem(i) + " column width: " + ItemBounds.Width);
  }
}

Python

def Main():
  # Obtain the Explorer process, window and the header control
  WshShell.Run("explorer.exe c:", SW_NORMAL)
  p = Sys.Process("Explorer")
  w = p.Window("CabinetWClass", "SYSTEM (C:)", 1).Window("SHELLDLL_DefView", "", 1).Window("DUIViewWndClassName", "", 1).Window("DirectUIHWND", "", 1).Window("CtrlNotifySink", "", 1).Window("SysListView32", "FolderView", 1)
  Header = w.Window("SysHeader32", "", 1)
  
  # Post the items' width to the test log
  ItemNumber = Header.wItemCount 
  for i in range(0, ItemNumber-1):
    ItemBounds = Header.wItemBounds[i]
    Log.Message(Header.wItem[i] + " column width: " + ItemBounds.Width)

VBScript

Sub Main
  Dim p, w, i, Header, ItemNumber, ItemBounds

  ' Obtain the Explorer process, window and the header control
  Call WshShell.Run("explorer.exe c:", SW_NORMAL)
  Set p = Sys.Process("Explorer")
  Set w = p.Window("CabinetWClass", "SYSTEM (C:)", 1).Window("SHELLDLL_DefView", "", 1).Window("DUIViewWndClassName", "", 1).Window("DirectUIHWND", "", 1).Window("CtrlNotifySink", "", 1).Window("SysListView32", "FolderView", 1)
  Set Header = w. Window("SysHeader32", "", 1)
  
  ' Post the items' width to the test log
  ItemNumber = Header.wItemCount
  For i = 0 To ItemNumber-1
    Set ItemBounds = Header.wItemBounds(i)
   Log.Message(Header.wItem(i) & " column width: " &ItemBounds.Width)
  Next 
End Sub

DelphiScript

procedure Main();
var 
  p, w, i, Header, ItemNumber, ItemBounds: OleVariant;
begin
  // Obtain the Explorer process, window and the header control
  WshShell.Run('explorer.exe c:', SW_NORMAL);
  p := Sys.Process('Explorer');
  w := p.Window('CabinetWClass', 'SYSTEM (C:)', 1).Window('SHELLDLL_DefView', '', 1).Window('DUIViewWndClassName', '', 1).Window('DirectUIHWND', '', 1).Window('CtrlNotifySink', '', 1).Window('SysListView32', 'FolderView', 1);
  Header := w.Window('SysHeader32', '', 1);
  
  // Post the items' width to the test log
  ItemNumber := Header.wItemCount;
  for i := 0 to ItemNumber-1 do
  begin
   ItemBounds := Header.wItemBounds(i);
   Log.Message(aqConvert.VarToStr(Header.wItem(i)) + ' column width: ' + aqConvert.VarToStr(ItemBounds.Width));
  end;
end;

C++Script, C#Script

function Main()
{
  var p, w, i, Header, ItemNumber, ItemBounds;

  // Obtain the Explorer process, window and the header control
  WshShell.Run("explorer.exe c:", SW_NORMAL);
  p = Sys["Process"]("Explorer");
  w = p["Window"]("CabinetWClass", "SYSTEM (C:)", 1)["Window"]("SHELLDLL_DefView", "", 1)["Window"]("DUIViewWndClassName", "", 1)["Window"]("DirectUIHWND", "", 1)["Window"]("CtrlNotifySink", "", 1)["Window"]("SysListView32", "FolderView", 1);
  Header = w["Window"]("SysHeader32", "", 1);
   
  // Post the items' width to the test log
  ItemNumber = Header["wItemCount"]
  for (i = 0; i<ItemNumber; i++)
  {
    ItemBounds = Header["wItemBounds"](i);
    Log["Message"](Header["wItem"](i) + " column width: " + ItemBounds["Width"]);
  }
}

See Also

Working With Header Controls in Desktop Windows Applications
wItemBounds Property (Header Controls)
Bounds Object

Highlight search results