_CountItems( ) API Library Routine Example

The following example creates a menu with three items, and calls _CountItems( ) to show that the function correctly returns the number of items on the menu. The routine then disposes of menu items, and calls _CountItems( ) again.

Visual FoxPro Code

SET LIBRARY TO CNTITEMS

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 CountItemsEx(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("\n_CountItems() ="); putLong(_CountItems(menuId));
   _Execute("WAIT");

   _DisposeItem(menuId, _GetItemId(menuId, 1));
   _PutStr("\n_CountItems() ="); putLong(_CountItems(menuId));
   _Execute("WAIT");

   _DisposeItem(menuId, _GetItemId(menuId, 0));
   _PutStr("\n_CountItems() ="); putLong(_CountItems(menuId));
   _Execute("WAIT");

   _DisposeMenu(menuId);
}

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