Getting Tab Pages' Images in Desktop Windows Applications

Applies to TestComplete 15.69, last modified on November 13, 2024

While testing tab 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.

Tab controls can display images next to tabs. You may need to obtain any of tabbed pages' images to process them. In this case, you can use specific properties and methods provided by the Win32TabControl object that corresponds to standard tab controls. The wImage property returns the Picture object that corresponds to the image of the tab specified by its index or caption. If the specified item does not have any image, the property returns an empty object.

After obtaining the image, you can process it in a special way using different methods provided by TestComplete. For more information on available methods of image processing, see the Picture object description. The following code snippet checks whether the specified item has an image. If a tabbed page has an image associated with it, the image is posted to the test log; otherwise, the script posts an informative message:

JavaScript

function main()
{
var p, l, w, TabControl, TabNumber;

  // Open My Computer
  WshShell.Run("explorer.exe /e, /select,C:\\", SW_SHOWNORMAL);

  // Obtain the tab control
  p = Sys.Process("Explorer");
  l = p.Window("ExploreWClass", "My Computer", 1);
  l.Keys("~T[Up][Enter]");
  w = p.Window("#32770", "Folder Options", 1);
  TabControl = w.Window("SysTabControl32", "", 1);
  
  // Determine the number of the tabs
  TabNumber = TabControl.wTabCount;
  
   // Checks whether the tabs have images
   for (let i = 0; i < TabNumber; i++)
     if (!strictEqual(TabControl.wImage(i), null))
       Log.Picture(TabControl.wImage(i), "Tab image");
     else
       Log.Message(TabControl.wTabCaption(i) + " tab does not have an image");
}

JScript

function main()
{
var p, l, w, i, TabControl, TabNumber;

  // Open My Computer
  WshShell.Run("explorer.exe /e, /select,C:\\", SW_SHOWNORMAL);

  // Obtain the tab control
  p = Sys.Process("Explorer");
  l = p.Window("ExploreWClass", "My Computer", 1);
  l.Keys("~T[Up][Enter]");
  w = p.Window("#32770", "Folder Options", 1);
  TabControl = w.Window("SysTabControl32", "", 1);
  
  // Determine the number of the tabs
  TabNumber = TabControl.wTabCount;
  
   // Checks whether the tabs have images
   for (i = 0; i < TabNumber; i++)
     if (TabControl.wImage(i) != null)
       Log.Picture(TabControl.wImage(i), "Tab image");
     else
       Log.Message(TabControl.wTabCaption(i) + " tab does not have an image");
}

Python

def Main():

  # Open My Computer
  WshShell.Run("explorer.exe /e, /select,C:\\", SW_SHOWNORMAL)

  # Obtain the tab control
  p = Sys.Process("Explorer")
  l = p.Window("ExploreWClass", "My Computer", 1)
  l.Keys("~T[Up][Enter]")
  w = p.Window("#32770", "Folder Options", 1)
  TabControl = w.Window("SysTabControl32", "", 1)
  
  # Determine the number of the tabs
  TabNumber = TabControl.wTabCount
  
  # Checks whether the tabs have images 
  for i in range(0, TabNumber-1): 
    if (TabControl.wImage(i) != None):
      Log.Picture(TabControl.wImage[i], "Tab image")
    else:
      Log.Message(TabControl.wTabCaption[i] + " tab does not have an image")

VBScript

Sub main
Dim p, l, w, i, TabControl, TabNumber

  ' Open My Computer
  Call WshShell.Run("explorer.exe /e, /select,C:\", SW_SHOWNORMAL)

  ' Obtain the tab control
  Set p = Sys.Process("Explorer")
  Set l = p.Window("ExploreWClass", "My Computer", 1)
  l.Keys "~T[Up][Enter]"
  Set w = p.Window("#32770", "Folder Options", 1)
  Set TabControl = w.Window("SysTabControl32", "", 1)
  
  ' Determine the number of the tabs
  TabNumber = TabControl.wTabCount
    
  ' Checks whether the tabs have images
   For i = 0 To TabNumber-1
     If Not (TabControl.wImage(i) Is Nothing) Then
       Call Log.Picture(TabControl.wImage(i), "Tab image")
     Else
       Log.Message(TabControl.wTabCaption(i) + " tab does not have an image")
     End If
   Next 
End Sub

DelphiScript

procedure Main();
var p, l, w, i, TabControl, TabNumber;
begin

  // Open My Computer
  WshShell.Run('explorer.exe /e, /select,C:\', SW_SHOWNORMAL);
  
  // Obtain the tab control
  p := Sys.Process('Explorer');
  l := p.Window('ExploreWClass', 'My Computer', 1);
  l.Keys('~T[Up][Enter]');
  w := p.Window('#32770', 'Folder Options', 1);
  TabControl := w.Window('SysTabControl32', '', 1);
  
  // Determine the number of the tabs
  TabNumber := TabControl.wTabCount;

   // Checks whether the tabs have images
   For i := 0 To TabNumber-1 do
     If (TabControl.wImage(i) <> nil)
     Then
       Log.Picture(TabControl.wImage(i), 'Tab image')
     Else
       Log.Message(TabControl.wTabCaption(i) + ' tab does not have an image');
end;

C++Script, C#Script

function main()
{
var p, l, w, i, TabControl, TabNumber;

  // Open My Computer
  WshShell["Run"]("explorer.exe /e, /select,C:\\", SW_SHOWNORMAL);

  // Obtain the tab control
  p = Sys["Process"]("Explorer");
  l = p["Window"]("ExploreWClass", "My Computer", 1);
  l.Keys("~T[Up][Enter]");
  w = p["Window"]("#32770", "Folder Options", 1);
  TabControl = w["Window"]("SysTabControl32", "", 1);
  
  // Determine the number of the tabs
  TabNumber = TabControl["wTabCount"];
  
  // Checks whether the tabs have images
  for (i = 0; i < TabNumber; i++)
    if (TabControl["wImage"](i) != null)
      Log["Picture"](TabControl["wImage"](i), "Tab image")
    else
      Log["Message"](TabControl["wTabCaption"](i) + " tab does not have an image");
}

See Also

Working With Tab Controls in Desktop Windows Applications
wImage Property (Specific to Win32Tab Controls)
Picture Object

Highlight search results