add_menu_action

add_menu_action — adds a menu action.

Syntax

add_menu_action (menu_id, s_exp)
    

Arguments

menu_id

A unique ID number for this item.

s_exp

A Gamma expression that is the action to be taken when a menu item is selected.

Returns

A list:

(menu_id s_exp)

Where the s_exp is in Lisp format.

Description

This function lets you specify what code gets run when a menu item is selected. The code can be removed using remove_menu_action

Example

This example is part of the WindowsExample.g example program:

method WindowsExample.AddSubMenu (parent, pos, label)
{
	local	submenu = CreatePopupMenu();
	InsertMenu (traymenu, pos, MF_BYPOSITION | MF_POPUP,
				submenu, label);
	.menu_items = cons (cons (submenu, t), .menu_items);
	submenu;
}

method WindowsExample.AddMenuItem (parent, pos, label, code)
{
	local	info = new MENUITEMINFO();
		
	info.cbSize = 48;
	info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
	info.fType = MFT_STRING;
	info.wID = ++MenuItemID;
	info.dwTypeData = label;
	InsertMenuItem (parent, pos, 1, info);
	local action = add_menu_action (MenuItemID, code);
	.menu_actions = cons (action, .menu_actions);
}

method WindowsExample.AddMenus ()
{
	local		traymenu = get_tray_menu ();

	if (traymenu != 0)
	{
		local	submenu = .AddSubMenu (traymenu, 5, "Monitor Functions");

		.AddMenuItem (submenu, -1, "Select Color", 
					  `(@self).SelectTrayMenuItem (@MenuItemID+1));
		.AddMenuItem (submenu, -1, "Select File",
					  `new GFileDialog (1).DoModal(0));
		.AddMenuItem (submenu, -1, "Select Folder",
					  `new GFolderDialog ().DoModal(0));
	}
	else
	{
	}
}