Changing Header Items' Width 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.

The header control is usually displayed above columns containing text or numeric information. If some column is not wide enough to display the whole text, you can resize it by changing the dimensions of the corresponding header item. You can use specific properties and methods of the Win32Header object to obtain data and perform various actions over the tested header control.

Before resizing the header items, you may need to determine whether the tested header control allows you to change the size of its items. To determine whether the specified header item can be resized, use the IsFixed property of the Win32HeaderItemFormat object. You can obtain this object via the wFormat property of the Win32Header object. For detailed information on how to obtain information about the tested header control using the properties of the Win32HeaderItemFormat object, see Determining Header Items' Format Settings in Desktop Windows Applications.

The following code snippet checks whether a header item can be resized:

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 fixed size
  ItemFormat = Header.wFormat(0);
  if (ItemFormat.IsFixed == true)
    Log.Message("The size of the item cannot be changed")
  else
    Log.Message("The size of the item can be changed")
}

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 fixed size
  ItemFormat = Header.wFormat[0]
  if ItemFormat.IsFixed:
    Log.Message("The size of the item cannot be changed")
  else:
    Log.Message("The size of the item can be changed")

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 fixed size
  Set ItemFormat = Header.wFormat(0)
  If ItemFormat.IsFixed = True Then
    Log.Message("The size of the item cannot be changed")
  Else
    Log.Message("The size of the item can be changed")
  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 specified header item has a fixed size
  ItemFormat := Header.wFormat(0);
  if (ItemFormat.IsFixed = true) then
    Log.Message('The size of the item cannot be changed')
  else
    Log.Message('The size of the item can be changed')
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 fixed size
  ItemFormat = Header["wFormat"](0);
  if (ItemFormat["IsFixed"] == true)
    Log["Message"]("The size of the item cannot be changed")
  else
    Log["Message"]("The size of the item can be changed")
}

If you need to set an arbitrary width for a certain column, you can do this via the Drag action. This action requires that you specify the coordinates of the starting point for dragging and the dragging distance in pixels. You can estimate the divider’s coordinates using the wItemBounds property. This property returns the Bounds object that contains data about the borders of the specified header item (see Determining Header Items' Bounds in Desktop Windows Applications).

You can also resize header items and columns that correspond to them by double-clicking the divider. A double-click on the specified divider resizes the header item to the left of it. In this case, the width of the column will fit the width of the column’s content. You can estimate the divider’s coordinates and use the DblClick action, but a more convenient way is using the DblClickDivider action. This action allows you to simulate a double-click on the divider specified by its number.

The following example demonstrates how you can resize header items:

JavaScript, JScript

function Main()
{
var p, w, Header, ItemBounds, x, y;

  // 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);
  
  // Estimate the first divider's coordinates
  ItemBounds = Header.wItemBounds(0);
  x = ItemBounds.Right;
  y = ItemBounds.Bottom;
  
  // Drag the divider
  Header.Drag(x+2, y-5, 20, 0);
  
  // Double-click the divider
  Header.DblClickDivider(0);

  // Estimate the second divider's coordinates and resize the second header item
  ItemBounds = Header.wItemBounds(1);
  x = ItemBounds.Right;
  y = ItemBounds.Bottom;
  Header.DblClick(ItemBounds.Right+2, ItemBounds.Bottom-5);
}

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)
  
  # Estimate the first divider's coordinates
  ItemBounds = Header.wItemBounds(0)
  x = ItemBounds.Right
  y = ItemBounds.Bottom
  
  # Drag the divider
  Header.Drag(x+2, y-5, 20, 0)
  
  # Double-click the divider
  Header.DblClickDivider(0)

  # Estimate the second divider's coordinates and resize the second header item
  ItemBounds = Header.wItemBounds[1]
  x = ItemBounds.Right
  y = ItemBounds.Bottom
  Header.DblClick(ItemBounds.Right+2, ItemBounds.Bottom-5)

VBScript

Sub Main
Dim p, w, Header, ItemBounds, x, y

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

  ' Estimate the first divider's coordinates
  Set ItemBounds = Header.wItemBounds(0)
  x = ItemBounds.Right
  y = ItemBounds.Bottom
  
  ' Drag the divider
  Header.Drag x+2, y-5, 20, 0
  
  ' Double-click the divider
  Header.DblClickDivider(0)

  ' Estimate the second divider's coordinates and resize the second header item
  Set ItemBounds = Header.wItemBounds(1)
  x = ItemBounds.Right
  y = ItemBounds.Bottom
  Header.DblClick ItemBounds.Right+2, ItemBounds.Bottom-5
End Sub

DelphiScript

procedure Main();
var 
  p, w, Header, ItemBounds, x, y: 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);
  
  // Estimate the first divider's coordinates
  ItemBounds := Header.wItemBounds(0);
  x := ItemBounds.Right;
  y := ItemBounds.Bottom;
  
  // Drag the divider
  Header.Drag(x+2, y-5, 20, 0);
  
  // Double-click the divider
  Header.DblClickDivider(0);

  // Estimate the second divider's coordinates and resize the second header item
  ItemBounds := Header.wItemBounds(1);
  x := ItemBounds.Right;
  y := ItemBounds.Bottom;
  Header.DblClick(ItemBounds.Right+2, ItemBounds.Bottom-5);
end;

C++Script, C#Script

function Main()
{
var p, w, Header, ItemBounds, x, y;

  // 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);
   
  // Estimate the first divider's coordinates
  ItemBounds = Header.wItemBounds(0);
  x = ItemBounds["Right"];
  y = ItemBounds["Bottom"];
  
  // Drag the divider
  Header["Drag"](x+2, y-5, 20, 0);
  
  // Double-click the divider
  Header["DblClickDivider"](0);

  // Estimate the second divider's coordinates and resize the second header item
  ItemBounds = Header["wItemBounds"](1);
  x = ItemBounds["Right"];
  y = ItemBounds["Bottom"];
  Header["DblClick"](ItemBounds["Right"]+2, ItemBounds["Bottom"]-5);
}

See Also

Working With Header Controls in Desktop Windows Applications
DblClick Action
DblClickDivider Action (Header Controls)
Drag Action
IsFixed Property (HeaderItemFormat Objects)
Determining Header Items' Bounds in Desktop Windows Applications
Determining Header Items' Format Settings in Desktop Windows Applications

Highlight search results