_EdPosInView( ) API Library Routine Example

The following example opens for editing a file specified by a parameter. After scrolling to the top of the file, the example calls _EdPosInView( ) to check whether the top of file and bottom of file are in view and the results are printed to the screen. Then the example scrolls to the bottom of the file, and again calls _EdPosInView( ) to check whether the top of file and bottom of file are in view.

Visual FoxPro Code

SET LIBRARY TO EDPOSINV
= POSINVIEW("x")

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 Example(ParamBlk FAR *parm)
{
#define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle))

   WHANDLE wh;
   EDENV EdEnv;

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

   _EdGetEnv(wh, &EdEnv);

   _EdScrollToPos(wh, 0, FALSE);
   _PutStr("\n_EdScrollToPos(wh, 0)");
   _PutStr("\n_EdPosInView(wh, 0) =");
   putLong(_EdPosInView(wh, 0));
   _PutStr("\n_EdPosInView(wh, EdEnv.length) =");
   putLong(_EdPosInView(wh, EdEnv.length));

   _EdScrollToPos(wh, EdEnv.length, FALSE);
   _PutStr("\n_EdScrollToPos(wh, EdEnv.length)");
   _PutStr("\n_EdPosInView(wh, 0) =");
   putLong(_EdPosInView(wh, 0));
   _PutStr("\n_EdPosInView(wh, EdEnv.length) =");
   putLong(_EdPosInView(wh, EdEnv.length));
}

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