Determining Header Items' Format Settings 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.

When testing a header control, you may need to obtain information about settings of a certain header item. TestComplete provides a special program object called Win32HeaderItemFormat that contains various information about header items. See the object description to learn what information it contains.

You can obtain the Win32HeaderItemFormat object via the wFormat property of the Win32Header object. TestComplete associates the Win32Header object with all header controls listed in the Object Mapping list of the project’s options. You can specify the needed header item by its index or caption.

The following sample code demonstrates how you can use the properties of the Win32HeaderItemFormat object:

JavaScript, JScript

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);
  
  // Check whether the specified header item has a check box
  ItemFormat = Header.wFormat(0)
  if (ItemFormat.HasCheckBox == true)
     Log.Message("An item has a check box")
  else Log.Message("An item does not have a check box")
}

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)
  
  # Check whether the specified header item has a check box
  ItemFormat = Header.wFormat[0] 
  if (ItemFormat.HasCheckBox == True):
    Log.Message("An item has a check box")
  else:
    Log.Message("An item does not have a check box")

VBScript

Sub Main
  Dim p, w, Header, ItemFormat

  ' 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)

  ' Check whether the specified header item has a check box
  Set ItemFormat = Header.wFormat(0)
  If ItemFormat.HasCheckBox = True Then 
    Log.Message("An item has a check box")
  Else Log.Message("An item does not have a check box")
  End If
End Sub 

DelphiScript

procedure Main();
var 
  p, w, i, Header, ItemFormat: 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);
  
  // Check whether the specified header item has a check box
  ItemFormat := Header.wFormat(0);
  if (ItemFormat.HasCheckBox = true) then 
    Log.Message('An item has a check box')
  else Log.Message('An item does not have a check box')
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);
  
  // Check whether the specified header item has a check box
  ItemFormat = Header["wFormat"](0);
  if (ItemFormat["HasCheckBox"] == true)
     Log["Message"]("An item has a check box")
  else Log["Message"]("An item does not have a check box")
}

See Also

Working With Header Controls in Desktop Windows Applications
wFormat Property (Header Controls)
Win32HeaderItemFormat Object

Highlight search results