_GetItemCmdKey( ) API Library Routine

JavaScript Editor js editor     Web development 



Main Page

Copies the displayed keyboard shortcut string for the specified menu item to the buffer pointed to by the text parameter.

int _GetItemCmdKey(MENUID menuid, ITEMID itemid, char FAR *text)
MENUID menuid;            /* Menu identifier. */
ITEMID itemid;            /* Menu item identifier. */
char FAR *text;            /* Where to store the shortcut string. */

Remarks

_GetItemCmdKey(В ) returns the internal keyboard code for the keyboard shortcut. If there is no keyboard shortcut for the specified menu item, _GetItemCmdKey(В ) returns 0.

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, setting up a keyboard shortcut for each item. It uses _GetItemCmdKey(В ) to display the shortcut keys.

Visual FoxPro Code

В Copy Code
SET LIBRARY TO GETICMDK

C Code

В Copy 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 GetItemCmdKeyEx(ParamBlk FAR *parm)
{
   MENUID menuId;
   ITEMID itemId;
   Point loc;
   char FAR *shortcutString;
   int intKeyCode;

   menuId = _GetNewMenuId();
   _NewMenu(MPOPUP, menuId);

   itemId = _GetNewItemId(menuId);
   _NewItem(menuId, itemId, -2, "\\<1st item");
   _SetItemCmdKey(menuId, itemId, altKey | 0x78, "Alt+1");

   itemId = _GetNewItemId(menuId);
   _NewItem(menuId, itemId, -2, "\\<2nd item");
   _SetItemCmdKey(menuId, itemId, altKey | 0x79, "Alt+2");

   itemId = _GetNewItemId(menuId);
   _NewItem(menuId, itemId, -2, "\\<3rd item");
   _SetItemCmdKey(menuId, itemId, altKey | 0x7a, "Alt+3");

   loc.v = 10; loc.h = 20;
   _SetMenuPoint(menuId, loc);

   _ActivateMenu(menuId);

   if ((shortcutString = _Alloca(64)) == 0)
   {
      _DisposeMenu(menuId);
      _Error(182); // "Insufficient memory"
   }
   intKeyCode = _GetItemCmdKey(menuId, _GetItemId(menuId, 0),
      shortcutString);
   _PutStr("\nShortcut string = "); _PutStr(shortcutString);
   _PutStr("\nInternal key code ="); putLong(intKeyCode);

   intKeyCode = _GetItemCmdKey(menuId, _GetItemId(menuId, 1),
      shortcutString);
   _PutStr("\nShortcut string = "); _PutStr(shortcutString);
   _PutStr("\nInternal key code ="); putLong(intKeyCode);

   intKeyCode = _GetItemCmdKey(menuId, _GetItemId(menuId, 2),
      shortcutString);
   _PutStr("\nShortcut string = "); _PutStr(shortcutString);
   _PutStr("\nInternal key code ="); putLong(intKeyCode);
   _Execute("WAIT");
   _DisposeMenu(menuId);
}

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

See Also



JavaScript Editor js editor     Web development