_GetItemText( ) API Library Routine Example

The following example creates a menu with three items and then retrieves the text of each item with _GetItemText( ).

Visual FoxPro Code

SET LIBRARY TO GETITEXT

C Code

#include <pro_ext.h>

FAR GetItemTextEx(ParamBlk FAR *parm)
{
   MENUID menuId;
   ITEMID itemId;
   Point loc;
   char FAR *itemText;

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

   if ((itemText = _Alloca(80)) == 0)
   {
      _Error(182); // "Insufficient memory"
   }
   _GetItemText(menuId, _GetItemId(menuId, 0), itemText);
   _PutStr("\nItem text of 1st item = "); _PutStr(itemText);

   _GetItemText(menuId, _GetItemId(menuId, 1), itemText);
   _PutStr("\nItem text of 2nd item = "); _PutStr(itemText);

   _GetItemText(menuId, _GetItemId(menuId, 2), itemText);
   _PutStr("\nItem text of 3rd item = "); _PutStr(itemText);

   _Execute("WAIT WINDOW");
   _DisposeMenu(menuId);
}

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