Determining the Number of Header Items in Desktop Windows Applications

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

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.

When working with header controls, you may need to obtain the number of its items, for example, if you want to obtain the items in order to process them. To work with header controls, you can use specific properties and methods of the Win32Header object. This object corresponds to header controls whose class names are listed in the Object Mapping list of the project’s options. You can obtain the total number of header items via the wItemCount property.

The following code snippet posts the total number of header items to the test log:

JavaScript, JScript

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

  // 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);
  
  // Post the number of header items to the log
  Log.Message("The number of items: " + Header.wItemCount);
}

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)
  
  # Post the number of header items to the log
  Log.Message("The number of items: " + Header.wItemCount)

VBScript

Sub Main
  Dim p, w, Header

  ' 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)
  
  ' Post the number of header items to the log
  Log.Message("The number of items: " & Header.wItemCount)
End Sub

DelphiScript

procedure Main();
var 
  p, w, Header: 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);
  
  // Post the number of header items to the log
  Log.Message('The number of items: ' + aqConvert.VarToStr(Header.wItemCount));
end;

C++Script, C#Script

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

  // 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);
   
  // Post the number of header items to the log
  Log.Message("The number of items: " + Header.wItemCount);
}

See Also

Working With Header Controls in Desktop Windows Applications
wItemCount Property (Header Controls)

Highlight search results