A basic demonstration for adding submenus to the in-sim Plugin menu.

#include "XPLMMenus.h"
#include <string.h>
#if IBM
	#include <windows.h>

#ifndef XPLM300
	#error This is made to be compiled against the XPLM300 SDK

int g_menu_container_idx; // The index of our menu item in the Plugins menu
XPLMMenuID g_menu_id; // The menu container we'll append all our menu items to
void menu_handler(void *, void *);

PLUGIN_API int XPluginStart(
						char *		outName,
						char *		outSig,
						char *		outDesc)
	strcpy(outName, "MenuPlugin");
	strcpy(outSig, "xpsdk.examples.menuplugin");
	strcpy(outDesc, "A sample plug-in that demonstrates and exercises the X-Plane menu API.");

	g_menu_container_idx = XPLMAppendMenuItem(XPLMFindPluginsMenu(), "Sample Menu", 0, 0);
	g_menu_id = XPLMCreateMenu("Sample Menu", XPLMFindPluginsMenu(), g_menu_container_idx, menu_handler, NULL);
	XPLMAppendMenuItem(g_menu_id, "Toggle Settings", (void *)"Menu Item 1", 1);
	XPLMAppendMenuItem(g_menu_id, "Toggle Shortcuts", (void *)"Menu Item 2", 1);
	XPLMAppendMenuItemWithCommand(g_menu_id, "Toggle Flight Configuration (Command-Based)", XPLMFindCommand("sim/operation/toggle_flight_config"));
	// Changed your mind? You can destroy the submenu you created with XPLMDestroyMenu(),
	// then remove the "Sample Menu" item from the "Plugins" menu with XPLMRemoveMenuItem().
	//XPLMRemoveMenuItem(XPLMFindPluginsMenu(), g_menu_container_idx);

	XPLMMenuID aircraft_menu = XPLMFindAircraftMenu();
	if(aircraft_menu) // This will be NULL unless this plugin was loaded with an aircraft (i.e., it was located in the current aircraft's "plugins" subdirectory)
		XPLMAppendMenuItemWithCommand(aircraft_menu, "Toggle Settings (Command-Based)", XPLMFindCommand("sim/operation/toggle_settings_window"));
	return 1;

PLUGIN_API void	XPluginStop(void)
	// Since we created this menu, we'll be good citizens and clean it up as well
	// If we were able to add a command to the aircraft menu, it will be automatically removed for us when we're unloaded

PLUGIN_API void XPluginDisable(void) { }
PLUGIN_API int XPluginEnable(void) { return 1; }
PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, int inMsg, void * inParam) { }

void menu_handler(void * in_menu_ref, void * in_item_ref)
	if(!strcmp((const char *)in_item_ref, "Menu Item 1"))
	else if(!strcmp((const char *)in_item_ref, "Menu Item 2"))

6 comments on “X-Plane Menu SDK Sample

  1. One Question,
    how can´t I find the method from the lib XPLM300 , XPLMFindAircraftMenu??
    Is ther a trick?

  2. Hi Tyler,
    amazing job with XP11! One other question: is there / will be there any way to “listen” to user clicks on menus other than “Plugins”. For example “Location”, “Settings”, etc… ? thx for your help.

      1. I’m working with an overlayed OS window which i need to hide when the user enters an XPlane “sim blocking” menu… a (working) workaround is to keep note of when the last FlightLoop occured (by using XPLMRegisterFlightLoopCallback), and hide my overlayed win (separate thread) when curtime is after X millisecs. Of course this brings some visible delay…

        1. Just to confirm: you have a popped-out, first-class X-Plane window… and you want it to disappear when there’s a modal window (like Settings or Flight Configuration) onscreen?

          The behavior that all the built-in windows exhibit in this situation is to simply darken and stop responding to input. (And this behavior comes free to SDK-created windows.)

Leave a Reply

Your email address will not be published. Required fields are marked *

Please do not report bugs in the blog comments.
Only bugs reported via the X-Plane Bug Reporter are tracked.