ChooseMenu

Windows management function.

The ChooseMenu function selects a menu item.

Syntax

ChooseMenu(normal,<menu_item>[,on or off])
ChooseMenu(system,<menu_item>[,on or off])
ChooseMenu(context,<menu_item>[,on or off])

or

ret=ChooseMenu(normal,<menu_item>[,on or off])
ret=ChooseMenu(system,<menu_item>[,on or off])
ret=ChooseMenu(context,<menu_item>[,on or off])

Parameters

normal, system, context : keywords defining the menu type, normal for menus inside applications, system for system menus, context for pop-up context menus.

<menu_item>, string, text of the menu item to be selected. During the time delay specified by #ActionTimeout, WinTask tries to find this item in the window specified by the last UseWindow statement and activates it. If the menu item is not found, an error is generated and the script is stopped. <menu_item> is a one string whatever special characters are in it - just use Recording mode for recording properly a menu selection.

on, off : keywords to check or uncheck the menu item ; this additional parameter is not generated by the Recording mode ; it must be added manually if needed.

Return value

Ret, numeric return code. When successful, the function returns 0, otherwise use this return code for error management.

Remarks

The variable #SendKeysDelay (0 as default value) slows down the selection.

Some Windows applications do not implement menu design using the standard Windows API functions, and then WinTask Recording mode is not able to record in an object-oriented way your menu selections, see the example below : menu selection by keyboard shortcut.

Context menus opened by right clicking the desktop are special too. See the example code below : context menu selection.

Example code - general

This script shows the different uses of the statement ChooseMenu in the application WordPad.

'Launch wordpad

 

shell("wordpad.exe")

UseWindow("WORDPAD.EXE|RICHEDIT|Document - WordPad|1",1)

SendKeys("test CHOOSEMENU<Enter>")

 

'ChooseMenu(Normal, )

 

UseWindow("WORDPAD.EXE|WordPadClass|Document - WordPad",1)

MsgBox("WinTask simulates the selection of the option Format|Font inside an application")

pause 2

ChooseMenu(Normal,"F&ormat|&Font...")

 

UseWindow("WORDPAD.EXE|#32770|Font",1)

Click(Button,"Cancel")

 

'ChooseMenu(Context, )

 

UseWindow("WORDPAD.EXE|WordPadClass|Document - WordPad",1)

MsgBox("WinTask simulates a text selection, a right click and Copy selection")

UseWindow("WORDPAD.EXE|RichEdit20A|Document - WordPad",1)

ClickMouse(Left,Down,13,17)

ClickMouse(Left,Up,13,17)

ClickMouse(Right,Down,89,19)

ClickMouse(Right,Up,89,19)

 

UseWindow("WORDPAD.EXE|WordPadClass|Document - WordPad",1)

ChooseMenu(Context,"&Copy")

 

'ChooseMenu(System, )

 

MsgBox("WinTask simulates the selection of the option Close in a system menu")

UseWindow("WORDPAD.EXE|WordPadClass|Document - WordPad",1)

ChooseMenu(System,"&Close Alt+F4")

 

UseWindow("WORDPAD.EXE|#32770|WordPad",1)

Click(Button,"&No")

 

Example code - menu selection by keyboard shortcut

 

Shell("notepad",1)

UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)

'The usual mode - selecting File/exit would be

'ChooseMenu(Normal,"&File|E&xit")

'Using shortcuts, the same action can be done with the lines below

SendKeys("<Alt f>")

'a small pause to give the system some relief

pause 3 ticks

Sendkeys("x")

 

Example code - context menu selection

 

'A first UseWindow to attach to the desktop
UseWindow("EXPLORER.EXE|SysListView32|FolderView",1)

'Click somewhere on the desktop
ClickMouse(Right,Down,682,514)

ClickMouse(Right,Up,682,514)

'The context menu is displayed
pause 3

'Press Down to select first option in the context menu ;
'We send the keys with option NoActivate for sending the keys where the cursor is
'whatever window is there.
Sendkeys("<Down>",Noactivate)

pause 5

Sendkeys("<Right>",Noactivate)

pause 3