_GetItemId( ) API Library Routine Example
The following example creates a menu with three items. It uses _GetItemId( ) to get the ITEMID of each menu item. After removing one item from the menu, you can see that the ITEMID isn't always equal to the item index.
SET LIBRARY TO GETIID
#include <pro_ext.h>
void putLong(long n)
{
Value val;
val.ev_type = 'I';
val.ev_long = n;
val.ev_width = 10;
_PutValue(&val);
}
FAR GetItemIdEx(ParamBlk FAR *parm)
{
MENUID menuId;
ITEMID itemId;
Point loc;
menuId = _GetNewMenuId();
_NewMenu(MPOPUP, menuId);
itemId = _GetNewItemId(menuId);
_NewItem(menuId, itemId, -2, "\\<1st item");
itemId = _GetNewItemId(menuId);
_NewItem(menuId, itemId, -2, "\\<2nd item");
itemId = _GetNewItemId(menuId);
_NewItem(menuId, itemId, -2, "\\<3rd item");
loc.v = 10; loc.h = 20;
_SetMenuPoint(menuId, loc);
_ActivateMenu(menuId);
_PutStr("\nitemid for index 0 ="); putLong(_GetItemId(menuId, 0));
_PutStr("\nitemid for index 1 ="); putLong(_GetItemId(menuId, 1));
_PutStr("\nitemid for index 2 ="); putLong(_GetItemId(menuId, 2));
_Execute("WAIT WINDOW");
_DisposeItem(menuId, _GetItemId(menuId, 1));
_PutStr("\nitemid for index 0 ="); putLong(_GetItemId(menuId, 0));
_PutStr("\nitemid for index 1 ="); putLong(_GetItemId(menuId, 1));
_Execute("WAIT WINDOW");
_DisposeMenu(menuId);
}
FoxInfo myFoxInfo[] = {
{"ONLOAD", (FPFI) GetItemIdEx, CALLONLOAD, ""},
};
FoxTable _FoxTable = {
(FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};