Getting Header Items' Images

Applies to TestComplete 14.93, last modified on September 27, 2021

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 images that are displayed within header items. You can use a set of specific properties and methods of the Win32Header object for this purpose. Each header item can display either a string or a bitmap. You can obtain an item's bitmap via the wBitmap property. Header items can also display an additional image, which is taken from the image list along with the string or bitmap. You can obtain the additional image of a header item using the wImage property.

Both properties return the Picture object that corresponds to the specified images. If the specified item does not have an image, wBitmap (or wImage) returns an empty object (null in JavaScript, JScript, C#Script and C++Script, None in Python, Nothing in VBScript, nil in DelphiScript).

TestComplete provides a set of specific methods that allow you to process images. For example, you can use the Log.Picture method to post images to the test log, save them to a file using the Picture.SaveToFile method, determine the size of an image via the Picture.Size property, and so on. See the Picture object description to get information on the available actions. The following sample code obtains the images that are associated with header items and posts them to the test log.

JavaScript

function Main()
{
  var p, w, Header, 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);
  
  // Post images to the test log
  ItemNumber = Header.wItemCount
  for (let i = 0; i<ItemNumber; i++)
  {
  if (!strictEqual(Header.wBitmap(i), null))
    Log.Picture(Header.wBitmap(i), "Current image");
  else
    Log.Message(Header.wItem(i) + " item does not have a bitmap image");
  if (!strictEqual(Header.wImage(i), null))
    Log.Picture(Header.wImage(i), "Additional image");
  else
    Log.Message(Header.wItem(i) + " item does not have an additional image");
  }
}

JScript

function Main()
{
  var p, w, i, Header, 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);
  
  // Post images to the test log
  ItemNumber = Header.wItemCount
  for (i = 0; i<ItemNumber; i++)
  {
  if (Header.wBitmap(i)!= null)
    Log.Picture(Header.wBitmap(i), "Current image");
  else
    Log.Message(Header.wItem(i) + " item does not have a bitmap image");
  if (Header.wImage(i) != null)
    Log.Picture(Header.wImage(i), "Additional image");
  else
    Log.Message(Header.wItem(i) + " item does not have an additional image");
  }
}

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 images to the test log
  ItemNumber = Header.wItemCount 
  for i in range(0, ItemNumber-1):
    if (Header.wBitmap[i] != None):
      Log.Picture(Header.wBitmap[i], "Current image")
    else:
      Log.Message(Header.wItem[i] + " item does not have a bitmap image")
    if (Header.wImage[i] != None):
      Log.Picture(Header.wImage[i], "Additional image")
    else:
      Log.Message(Header.wItem[i] + " item does not have an additional image")

VBScript

Sub Main
  Dim p, w, i, Header, 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)
  
  ' Post images to the test log
  ItemNumber = Header.wItemCount
  For i = 0 To ItemNumber-1
    If Not (Header.wBitmap(i) Is Nothing) Then
      Call Log.Picture(Header.wBitmap(i), "Current image")
    Else
      Log.Message(Header.wItem(i) + " item does not have a bitmap image")
    End If
    If Not (Header.wImage(i) Is Nothing) Then
      Call Log.Picture(Header.wImage(i), "Additional image")
    Else
      Log.Message(Header.wItem(i) + " item does not have an additional image")
    End If
  Next 
End Sub

DelphiScript

procedure Main();
var 
  p, w, i, Header, 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);
  
   // Post images to the test log
  ItemNumber := Header.wItemCount;
  for i := 0 to ItemNumber-1 do
  begin
  if (Header.wBitmap(i) <> nil)
  then
    Log.Picture(Header.wBitmap(i), 'Current image')
  else
    Log.Message(Header.wItem(i) + ' item does not have a bitmap image');
  if (Header.wImage(i) <> nil)
  then
    Log.Picture(Header.wImage(i), 'Additional image')
  else
    Log.Message(Header.wItem(i) + ' item does not have an additional image');
  end;
end;

C++Script, C#Script

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

  // 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 images to the test log
  ItemNumber = Header.wItemCount
  for (i = 0; i<ItemNumber; i++)
  {
  if (Header["wBitmap"](i)!= null)
    Log["Picture"](Header["wBitmap"](i), "Current image");
  else
    Log["Message"](Header["wItem"](i) + " item does not have a bitmap image");
  if (Header["wImage"](i) != null)
    Log["Picture"](Header["wImage"](i), "Additional image");
  else
    Log["Message"](Header["wItem"](i) + " item does not have an additional image");
  }
}

When working with header items, you may need to check whether the specified item has an image or a bitmap. You can perform this check as it is described in the example above, but there is one more approach that is based on using the Win32HeaderItemFormat object. You can obtain this object via the wFormat property of the Win32Header object. Win32HeaderItemFormat provides the following properties to work with header items’ images:

  • HasImage - Returns True if the specified item has an additional image.
  • IsBitmap - Returns True if the specified item displays a bitmap.
  • IsBitmapOnRight - Returns True if the bitmap is displayed to the right of the header item's text.

The following sample code demonstrates how you can use the above-mentioned properties of the Win32HeaderItemFormat object. It checks whether the second item has images and posts informative messages to the test log:

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 second item has assigned images
  ItemFormat = Header.wFormat(1);
  if (ItemFormat.HasImage == false)
      Log.Message("There is no additional image")
    else Log.Message("The " + Header.wItem(1) + "item has an image")
  if (ItemFormat.IsBitmap == true)
  {
    if (ItemFormat.IsBitmapOnRight == true)
        Log.Message("The bitmap is to the right of the text")
     else 
        Log.Message("The bitmap is to the left of the text")
  }
    else Log.Message("There is no bitmap")
}

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 second item has assigned images
  ItemFormat = Header.wFormat(1)
  if (ItemFormat.HasImage == False):
    Log.Message("There is no additional image")
  else:
    Log.Message("The " + Header.wItem[1] + "item has an image")
  if (ItemFormat.IsBitmap == True):
    if (ItemFormat.IsBitmapOnRight == True) :
      Log.Message("The bitmap is to the right of the text")
    else:
      Log.Message("The bitmap is to the left of the text")
  else:
   Log.Message("There is no bitmap")

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 second item has assigned images
  Set ItemFormat = Header.wFormat(1)
  If ItemFormat.HasImage = False Then 
      Log.Message("There is no additional image")
    Else Log.Message("The " & Header.wItem(1) & "item has an image")
  End If
  If ItemFormat.IsBitmap = True Then
    If ItemFormat.IsBitmapOnRight = True Then 
        Log.Message("The bitmap is to the right of the text")
      Else 
        Log.Message("The bitmap is to the left of the text")
    End If
    Else Log.Message("There is no bitmap")
  End If
End Sub

DelphiScript

procedure Main();
var 
  p, w, 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 second item has assigned images
  ItemFormat := Header.wFormat(1);
  if ItemFormat.HasImage = false
  then
    Log.Message('There is no additional image')
  else 
  Log.Message('The ' + aqConvert.VarToStr(Header.wItem(1)) + 'item has an image');
   
  if ItemFormat.IsBitmap = true then
  begin
    if ItemFormat.IsBitmapOnRight = true then
       Log.Message('The bitmap is to the right of the text')
    else
       Log.Message('The bitmap is to the left of the text')
  end
  else
  begin
    Log.Message('There is no bitmap')
  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);
   
  // Check whether the second item has assigned images
  ItemFormat = Header["wFormat"](1);
  if (ItemFormat["HasImage"] == false)
      Log["Message"]("There is no additional image")
    else Log["Message"]("The " + Header["wItem"](1) + "item has an image")
  if (ItemFormat["IsBitmap"] == true)
  {
    if (ItemFormat["IsBitmapOnRight"] == true)
        Log["Message"]("The bitmap is to the right of the text")
      else 
        Log["Message"]("The bitmap is to the left of the text")
  }
    else Log["Message"]("There is no bitmap")
}

See Also

Working With Header Controls
wBitmap Property (Header Controls)
wImage Property (Header Controls)
Picture Object

Highlight search results