Share via


_NewItem( ) API Library Routine

Adds an item with the specified identifier itemid to the menu specified by menuid.

int _NewItem(MENUID menuid, ITEMID itemid, ITEMID 
beforeid, char FAR *prompt)
MENUID menuid;            /* Menu identifier. */
ITEMID itemid;            /* New item identifier. */
ITEMID beforeid;            /* Identifier of item the new item
 precedes. */
char FAR *prompt;         /* Text for new menu item. */

Remarks

The type of the new menu item is automatically a menu title or a bar, depending on the type of menu into which the item is being inserted.

The beforeid parameter specifies the identifier of the item the new item is to precede. Specify beforeid as – 1 to specify the new item will be the first item in the list, or as -2 to specify the item is to be added at the end of the list. The prompt specifies the text for the new menu item. _NewItem( ) returns 0 if it succeeds in adding an item, or – 1 if not.

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 builds a menu with three items. It uses _NewItem( ) to add each item to the menu.

Visual FoxPro Code

SET LIBRARY TO NEWITEM 

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, "\\<2nd item");

   itemId = _GetNewItemId(menuId);
   _NewItem(menuId, itemId, -1, "\\<1st 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

_SetItemCmdKey( ) API Library Routine | _SetItemSubMenu( ) API Library Routine | Accessing the Visual FoxPro API