Checking Menu Items. Example

Applies to TestComplete 15.47, last modified on January 20, 2023

The following code checks the Tool Box and Color Box menu items on the View menu of MSPaint, which must be running.

JavaScript, JScript

function TestProc()
{
  var p, w;

  p = Sys.Process("mspaint");
  w = p.Window("MSPaintApp", "*");

  if (w.Exists)
  {
    // If MSPaint is minimized,
    // the following line will restore it on screen
    w.Restore();

    w.MainMenu.Check("View|Tool Box", true);
    w.MainMenu.Check("View|Color Box", true);
  }
}

Python

def TestProc():

  p = Sys.Process("mspaint")
  w = p.Window("MSPaintApp", "*")

  if (w.Exists):
    # If MSPaint is minimized,
    # the following line will restore it on screen
    w.Restore()

    w.MainMenu.Check("View|Tool Box", True)
    w.MainMenu.Check("View|Color Box", True)

VBScript

Sub TestProc
  Dim p, w

  Set p = Sys.Process("mspaint")
  Set w = p.Window("MSPaintApp", "*")

  If w.Exists Then
    ' If MSPaint is minimized,
    ' the following line will restore it on screen
    w.Restore

    Call w.MainMenu.Check("View|Tool Box", True)
    Call w.MainMenu.Check("View|Color Box", True)
  End If
End Sub

DelphiScript

procedure TestProc;
var p, w : OleVariant;
begin
  p := Sys.Process('mspaint');
  w := p.Window('MSPaintApp', '*');

  if w.Exists then
  begin
    // If MSPaint is minimized,
    // the following line will restore it on screen
    w.Restore;

    w.MainMenu.Check('View|Tool Box', true);
    w.MainMenu.Check('View|Color Box', true);
  end;
end;

C++Script, C#Script

function TestProc()
{
  var p, w;

  p = Sys["Process"]("mspaint");
  w = p["Window"]("MSPaintApp", "*");

  if (w["Exists"])
  {
    // If MSPaint is minimized,
    // the following line will restore it on screen
    w["Restore"]();

    w["MainMenu"]["Check"]("View|Tool Box", true);
    w["MainMenu"]["Check"]("View|Color Box", true);
  }
}

See Also

Working With Menus in Desktop Windows Applications
Simulating Menu Actions

Highlight search results