Condividi tramite


_EdSetPos( ) API Library Routine

Moves the insertion point to the specified offset position in the file in the specified editing window, unselecting any selected text.

void _EdSetPos(WHANDLE wh, EDPOS thePos)
WHANDLE wh;            /* Handle of editing window. */
EDPOS thePos;               /* Specified offset position. */

Example

The following example opens for editing a file specified by a parameter. Using _EdSetPos( ), it sets the insertion point to position 19 of the file. It calls _EdGetPos( ) and inserts some text to verify that the insertion point has been set.

Visual FoxPro Code

SET LIBRARY TO EDSETPOS
= EDSETPOS('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_READWRITE);
   _HUnLock(parm->p[0].val.ev_handle);

   _EdSetPos(wh, 19);
   _PutStr("\n_EdSetPos(wh, 19)");
   edpos = _EdGetPos(wh);
   _PutStr("\n_EdGetPos(wh) ="); putLong(edpos);
   _EdInsert(wh, "*** Inserted at EDPOS = 19 ***",
      _StrLen("*** Inserted at EDPOS = 19 ***"));
}

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

See Also

Reference

_EdGetLineNum( ) API Library Routine

_EdGetChar( ) API Library Routine

_EdGetPos( ) API Library Routine