menu Overview


The menu object wraps the standard Windows menu. Such an object can be obtained by calling wnd.menu on any window to retrieve a reference to its menu bar, or by calling menu.menu to get a reference to a submenu.

// This is a reference to the main window menu (ie the one which contains File, Edit, View ...)
var menubar = app.menu;

// Print the number of items in the 'Edit' menu
Env.LogInfo(menubar.menu("&Edit").count);

// Select the File/Open command
menubar.menu("&File").select("&Open");

Dynamic menus (such as the right-click context menus) are common controls which mimic menu behaviour. They are not standard window menus, therefore they cannot be manipulated using this wrapper object and they must be dealt with in particular ways. The following function shows how to use waitForWindow and MS Accessibility to control the most common case of a context popup menu:

function getContextMenu(wndParent)
{
// Wait for the context menu window to appear
	var cmwnd = docwnd.waitForWindow(0, consts.MENU_CLASS);

// The first child of the menu window is the menu itself
	return cmwnd.accNavigate(consts.NAVDIR_FIRSTCHILD);
}

Here's an example of how to use the above function to access the right click context menu in Internet Explorer:

// Attach IE's HTML window and right click on it
	app.appAttach("\\.*Microsoft Internet Explorer.*"); // assuming that IE is already started
	var docwnd = app.wnd(0, consts.MSHTML_CLASS); // get its HTML window
	docwnd.click(consts.MB_RIGHTBUTTON); // right click to show the context menu

// Wait for the menu to appear
	var cm = getContextMenu(docwnd);

// Test our object: display all menu items
	var count = cm.accChildCount;
	for (i=1; i<=count; i++)
		Env.LogInfo(cm.accName(i));

Methods

select Selects (simulates a click on) the specified menu item.

Properties

menu (Inherited from wnd) Returns a reference to a submenu.
count Returns the number of menu items.

 


© 2003 Lightweight Technologies. All rights reserved.