> For the complete documentation index, see [llms.txt](https://raia-software-inc.gitbook.io/tacview-2-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://raia-software-inc.gitbook.io/tacview-2-documentation/api-reference/api-reference/menus/get-main-menu-handle.md).

# GetMainMenuHandle()

Returns the handle of Tacview's main menu.

## Syntax

```lua
mainMenuHandle = GetMainMenuHandle()
```

## Parameters

This function has no parameters.

## Return value

Returns the handle of the main menu.

Returns `nil` if the main menu is not available. This can happen if the add-on is loaded before Tacview has created the main menu, or if the main menu has already been destroyed while Tacview is shutting down. In normal use, this should be rare.

## Remarks

A menu handle identifies one complete menu hierarchy. This hierarchy may contain items and submenus.

Add-ons typically use `GetMainMenuHandle()` to add their own commands to Tacview's main menu with `AddMenuItem()`, check menu interactions with `WasMenuItemClicked()`, update menu item state, and remove their items when the add-on shuts down.

When adding menu items to the main menu, choose the most appropriate path and group so the new command appears in a logical place for the user.

The main menu is a shared menu. Be considerate when choosing item ids, groups, order values, and shortcuts. Add-ons should place commands where users naturally expect to find them.

Menu items added by an add-on to the main menu should be removed when the add-on shuts down. This prevents Tacview from keeping inactive commands in the main menu if the add-on is disabled or unloaded while Tacview continues running.

## Example

This example adds a command to the main menu during initialization and removes it during shutdown.

```lua
local DogfightAnalysisMenuId = "DogfightAnalysis"

function PluginInitialize()

	local mainMenuHandle = GetMainMenuHandle()

	if mainMenuHandle then

		AddMenuItem(mainMenuHandle, {
			path = "Analysis",
			group = "Charts",
			id = DogfightAnalysisMenuId,
			label = "Dogfight Analysis"
		})

	end

end

function PluginShutdown()

	local mainMenuHandle = GetMainMenuHandle()

	if mainMenuHandle then

		RemoveMenuItem(mainMenuHandle, DogfightAnalysisMenuId)

	end

end
```

## See also

* `AddMenuItem()`
* `WasMenuItemClicked()`
* `SetMenuItemEnabled()`
* `SetMenuItemChecked()`
* `CheckExclusiveMenuItem()`
* `RemoveMenuItem()`
