Share via


_GetNewItemId( ) API Library Routine

Returns an identifier that's currently available for use as an item identifier in the specified menu.

ITEMID _GetNewItemId(MENUID menuid)
MENUID menuid;            /* Menu identifier. */

Remarks

Every item in a menu must have an identifier that's unique to that menu.

After using _GetNewItemId( ), add the new item to the menu with _NewItem( ) before using _GetNewItemId( ) again. If you don't add the item to the menu, subsequent calls to _GetNewItemId( ) return the same ITEMID.

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. Before each item is added to the menu, a unique ITEMID is generated by calling _GetNewItemId( ).

Visual FoxPro Code

SET LIBRARY TO GETNWIID

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 GetNewItemId(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);

   _MenuInteract(&menuId, &itemId);

   _PutStr("\nmenuId ="); putLong(menuId);
   _PutStr("\nitemId ="); putLong(itemId);

   _DisposeMenu(menuId);
}

FoxInfo myFoxInfo[] = {
   {"ONLOAD", (FPFI) GetNewItemId, CALLONLOAD, ""},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

Reference

_GetItemId( ) API Library Routine

_SetItemText( ) API Library Routine

_NewItem( ) API Library Routine

_GetNewMenuId( ) API Library Routine

Other Resources

API Library Construction

Accessing the Visual FoxPro API