Run Menu Command statement - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Runs a MapInfo Pro menu command, as if the user had selected the menu item. Can also be used to select a button on a ButtonPad. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

Run Menu Command { command_code | ID command_ID } 

command_code is an integer code from MENU.DEF (such as M_FILE_NEW), representing a standard menu item or button.

command_ID is a number representing a custom menu item or button.

Description

To execute a standard MapInfo Pro menu command, include the command_code parameter. The value of this parameter must match one of the menu codes listed in MENU.DEF. For example, the following MapBasic statement executes MapInfo Pro's File > New command:

Run Menu Command M_FILE_NEW

To select a standard button from MapInfo's ButtonPads, specify that button's code (from MENU.DEF). For example, the following statement selects the Radius Search button:

Run Menu Command M_TOOLS_SEARCH_RADIUS

To select a custom button or menu command (for example, a button or a menu command created through a MapBasic program), use the ID clause.

For example, if your program creates a custom tool button by issuing a statement such as...

Alter ButtonPad ID 1 Add
	ToolButton 
		Calling sub_procedure_name
		ID 23 
		Icon MI_ICON_CROSSHAIR 

...then the custom button has an ID of 23. The following statement selects the button.

Run Menu Command ID 23 

Using MapBasic, the Run Menu Command statement can execute the MapInfo Pro Help > MapInfo Pro Tutorial on the Web command.

Run Menu Command M_HELP_MAPINFO_WWW_TUTORIAL

You can access Query > Invert Selection using the following MapBasic command:

Run Menu Command M_QUERY_INVERTSELECT.

Access Page settings in Options > Preferences > Printer by using the following syntax:

RUN MENU COMMAND M_EDIT_PREFERENCES_PRINTER

To launch a web page with a repository of MapBasic applications written by people in the MapInfo Pro community use M_MBTOOL_GET_MB_UTILITIES.

RUN MENU COMMAND M_MBTOOL_GET_MB_UTILITIES

See Also:

Run Application statement, Run Program statement

Integrated Mapping Applications

Integrated Mapping applications cannot display the Layer Control as a window. However, Integrated Mapping applications can display the Layer Control as a modal dialog box, by using the Run Menu Command statement with command M_MAP_LAYER_CONTROL_DIALOG. For example:

Run Menu Command M_MAP_LAYER_CONTROL_DIALOG

Preferences Dialog Box

MapInfo Pro's Preferences dialog box is a special case. The Preferences dialog box contains several buttons, each of which displays another dialog box. You can use Run Menu Command statement to invoke individual sub-dialog boxes. For example, the following statement displays the Map Window Preferences sub-dialog box:

Run Menu Command M_EDIT_PREFERENCES_MAP

Bringing Windows to the Front

To bring windows listed in the Window menu’s window list to the front, use M_WINDOW_FIRSTWIN.

Run Menu Command M_WINDOW_FIRSTWIN

You can also use this command when you want to bring a window frame to the front of a layout in a Layout window.

M_WINDOW_FIRSTWIN refers only to the first window in that list. The following is a sample window list that shows Map (WORLDCAP, world Map:1), Layout (Layout Designer:1), Browser (WORLDCAP Browser), and classic Layout (Layout:1) windows that are open in a MapInfo Pro session:

  • WORLDCAP, world Map:1
  • Layout Designer:1
  • WORLDCAP Browser
  • WORLDCAP, world Map:2
  • Layout Designer:2
  • WORLDCAP, world Map:3
  • Layout Designer:2
  • Layout:1
Note: For background on classic Layout windows, see Working with Classic Layout Windows.

The following command brings WORLDCAP, world Map:1 to the front.

Run Menu Command M_WINDOW_FIRSTWIN

The following brings the next window Layout Designer:1 to the front:

Run Menu Command M_WINDOW_FIRSTWIN + 1

Any window in that list, including embedded windows in a Layout window, is brought to the front using the following command where (n - 1) is the number of the window minus one:

Run Menu Command M_WINDOW_FIRSTWIN + (n - 1)

As an example, if you want to bring the seventh window (Layout Designer:2) to the front:

Run Menu Command M_WINDOW_FIRSTWIN + 6

Layer Control Window and Dialog Box

MapInfo Pro 10.0 and higher display the Layer Control as a window and not as a dialog box. As of MapBasic 10.0, MapBasic applications can display the Layer Control as either a window or as a dialog box by executing a Run Menu command statement:

  • To display Layer Control as a window, use M_MAP_LAYER_CONTROL:
Run Menu Command M_MAP_LAYER_CONTROL
  • To display Layer Control as a dialog box (with OK and Cancel buttons), use M_MAP_LAYER_CONTROL_DIALOG:
Run Menu Command M_MAP_LAYER_CONTROL_DIALOG

Releases before MapInfo Pro 10.0 display the Layer Control as a dialog box, so MapBasic applications (MBX) written with MapBasic 9.5 or earlier assume that the Layer Control is a dialog box. To be backwards compatible, MapInfo Pro 10.0 and higher executes older MapBasic applications that requests the Layer Control, using a Layer Control dialog box.

To control whether your MapBasic application (MBX) displays Layer Control as a window or a dialog box:

  • If you recompile your MBX in MapBasic 10.0 (using the updated MENU.DEF from MapBasic 10.0), then the new MBX displays Layer Control as a window, not as a dialog box. This is ideal for most situations, because MapInfo Pro 10.0 users expect Layer Control to display as a window.
  • If you have recompiled your MBX in MapBasic 10.0, but you want to continue displaying Layer Control as a dialog box, update your Run Menu Command as follows:
Run Menu Command M_MAP_LAYER_CONTROL_DIALOG

About the Layer Control Dialog Box

The Layer Control dialog box has fewer features compared to the Layer Control window. The following occur with the Layer Control dialog and not the Layer Control window:

  • The Move Up and Move Down buttons are disabled if there are groups in the map.
  • When you right-click on a layer, there is no context menu. As a result, most Group layer operations are not available.
  • You are unable to move theme layers.