Condividi tramite


_OnSelection( ) API Library Routine

Specifies a routine to execute when the user chooses the specified menu and item.

void _OnSelection(MENUID menuid, ITEMID itemid, FPFI routine)
MENUID menuid;            /* Menu identifier. */
ITEMID itemid;            /* Item identifier. */
FPFI routine;               /* Routine to execute. */

Remarks

If you specify itemid as – 1, the routine executes when the user chooses any item on the menu. A routine associated with an individual item overrides one associated with the entire menu. To cancel a selection routine for a specified menu and item, pass (FPFI)0 as the routine parameter.

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 calls _OnSelection( ) with an ITEMID parameter of –1, indicating that the function USERCHOICE( ) is to be called when the user chooses any item from this menu.

Visual FoxPro Code

SET LIBRARY TO ONSELECT

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 onSelection(long menuId, long itemId)
{
   _PutStr("\nitemId = "); putLong(itemId);
   _DisposeMenu(menuId);
}

FAR activateMenu(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);
   _OnSelection(menuId, -1, onSelection);
}

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

See Also

Accessing the Visual FoxPro API | _ActivateMenu( ) API Library Routine | _MenuInteract( ) API Library Routine