Getting Header Items 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.

Header controls are usually divided into several labeled parts displayed above columns containing information. You may need to obtain items’ captions to work with them from your tests. If the class name of the tested header control is specified in the Object Mapping list of the project’s options, you can use the Win32Header object to operate with the control. You can obtain the needed item specified by its index via the wItem property.

To check whether the specified item has a caption, use the IsString property of the Win32HeaderItemFormat object. You can obtain this object via the wFormat property of Win32Header. For detailed information on how to work with Win32HeaderItemFormat, see Determining Header Items' Format Settings in Desktop Windows Applications.

The following sample code obtains the captions of all header items and posts them to the test log. If an item does not have a caption, it posts an informative message to the test log:

JavaScript, JScript

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

  // 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);
  w.Keys("[Apps]");
  w.PopupMenu.Click("View|Details");
  Header = w.Window("SysHeader32", "", 1);
  ItemFormat = Header.wFormat(0)
  
  // Determine the total number of items
  ItemNumber = Header.wItemCount;
  
  // Obtain the header items
  for (i = 0; i < ItemNumber; i++)
  {
    if (ItemFormat.IsString == true)
      Log.Message(Header.wItem(i))
    else
      Log.Message("The item does not have a caption")
  }
}

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)
  w.Keys("[Apps]")
  w.PopupMenu.Click("View|Details")
  Header = w.Window("SysHeader32", "", 1)
  ItemFormat = Header.wFormat(0) 
  
  # Determine the total number of items
  ItemNumber = Header.wItemCount
  
  # Obtain the header items
  for i in range(0, ItemNumber-1):
    if ItemFormat.IsString:
      Log.Message(Header.wItem[i])
    else:
      Log.Message("The item does not have a caption")

VBScript

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

  ' 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)
  w.Keys "[Apps]"
  w.PopupMenu.Click("View|Details")
  Set Header = w. Window("SysHeader32", "", 1)
  Set ItemFormat = Header.wFormat(0)
  
  ' Determine the total number of items
  ItemNumber = Header.wItemCount
  
  ' Obtain the header items
  For i = 0 To ItemNumber-1
    If ItemFormat.IsString = True Then 
      Log.Message(Header.wItem(i))
    Else Log.Message("The item does not have a caption")
    End If
  Next
End Sub 

DelphiScript

procedure Main();
var 
  p, w, i, Header, ItemFormat, ItemNumber: 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);
  w.Keys('[Apps]');
  w.PopupMenu.Click('View|Details');
  Header := w.Window('SysHeader32', '', 1);
  ItemFormat := Header.wFormat(0);
  
  // Determine the total number of items
  ItemNumber := Header.wItemCount;
  
  // Obtain the header items
  for i := 0 to ItemNumber-1 do
  begin
    if (ItemFormat.IsString = true) then
      Log.Message(aqConvert.VarToStr(Header.wItem(i)))
    else
      Log.Message('The item does not have a caption')
  end;
end;

C++Script, C#Script

function Main()
{
var  p, w, Header, ItemFormat;

  // 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);
  w["Keys"]("[Apps]");
  w["PopupMenu"]["Click"]("View|Details");
  Header = w["Window"]("SysHeader32", "", 1);
  ItemFormat = Header["wFormat"](0);
  
  // Determine the total number of items
  ItemNumber = Header["wItemCount"];
  
  // Obtain the header items
  for (i = 0; i < ItemNumber; i++)
  {
    if (ItemFormat["IsString"] == true)
      Log.Message(Header["wItem"](i))
    else
      Log.Message("The item does not have a caption")
  }
}

See Also

Working With Header Controls in Desktop Windows Applications
wItem Property (Header Controls)
IsString Property (HeaderItemFormat Objects)
Determining Header Items' Format Settings in Desktop Windows Applications

Highlight search results