add_menu_action (menu_id, s_exp)
A unique ID number for this item.
A Gamma expression that is the action to be taken when a menu item is selected.
This function lets you specify what code gets run when a menu item is selected. The code can be removed using remove_menu_action
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 { } }
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.