Share via


_EdGetPos( ) API Library Routine

Returns the current offset position of the insertion point in the file in the specified editing window.

EDPOS _EdGetPos(WHANDLE wh)
WHANDLE wh;            /* Handle of editing window. */

Remarks

If text is selected, _EdGetPos( ) returns the offset position of the anchor.

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 opens an edit session for a file specified by a parameter. After setting the current insertion point with _EdSetPos( ), a call to _EdGetPos( ) is made to verify that it returns the insertion point offset position. After selecting text with _EdSelect( ), a call to _EdGetPos( ) is made to verify that it returns the anchor point offset position.

Visual FoxPro Code

SET LIBRARY TO EDGETPOS
= EDGETPOS("x")

C Code

#include <pro_ext.h>

void putLong(long n)
{
   Value val;

   val.ev_type = 'I';
   val.ev_long = n;
   val.ev_width = 6;

   _PutValue(&val);
}

FAR Example(ParamBlk FAR *parm)
{
#define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle))

   WHANDLE wh;
   EDPOS edpos;

   if (!_SetHandSize(parm->p[0].val.ev_handle,
      parm->p[0].val.ev_length+1))
   {
      _Error(182); // "Insufficient memory"
   }
   pFILENAME[parm->p[0].val.ev_length] = '\0';

   _HLock(parm->p[0].val.ev_handle);
   wh = _EdOpenFile(pFILENAME, FO_READONLY);
   _HUnLock(parm->p[0].val.ev_handle);

   _EdSetPos(wh, 19);
   _PutStr("\n_EdSetPos(wh, 19)");
   edpos = _EdGetPos(wh);
   _PutStr("\n_EdGetPos(wh) ="); putLong(edpos);

   _EdSelect(wh, 5, 12);
   _PutStr("\n_EdSelect(wh, 5, 12)");
   edpos = _EdGetPos(wh);
   _PutStr("\n_EdGetPos(wh) ="); putLong(edpos);
}

FoxInfo myFoxInfo[] = {
   {"EDGETPOS", (FPFI) Example, 1, "C"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

_EdGetChar( ) API Library Routine | _EdSetPos( ) API Library Routine | _EdGetLinePos( ) API Library Routine