Share via


_GetItemId( ) API Library Routine

Returns the item identifier of the specified item in the specified menu.

ITEMID _GetItemId(MENUID menuid, long index)
MENUID menuid;            /* Menu identifier. */
long index;                  /* Menu item number. */

Remarks

You can use _GetItemId( ) to gather menu bar or menu identifiers, so you can perform an operation on all the items. _GetItemId( ) returns 0 when index exceeds the number of items on the menu.

For more information on how to create an API library and integrate it with Visual FoxPro, see Accessing the Visual FoxPro API.

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.

Visual FoxPro Code

SET LIBRARY TO GETIID  

C Code

#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
};

See Also

Reference

_GetItemSubMenu( ) API Library Routine

_GetNewItemId( ) API Library Routine

NewItemID Property

Other Resources

API Library Construction

Accessing the Visual FoxPro API