Compartir a través de


_EdScrollToSel( ) API Library Routine

Ensures that the selected text in the designated window is visible.

void _EdScrollToSel(WHANDLE wh, int Center)
WHANDLE wh;            /* Handle of editing window. */
int Center;                  /* Whether to center anchor point in
 window. */

Remarks

Specify Center as TRUE to center the anchor point vertically in the window, or as FALSE to not center the anchor point.

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 for editing a file specified by a parameter. The example makes a selection near the bottom of the file. After the user presses a key in response to a Visual FoxPro WAIT command, the example scrolls the editing window to the selection by calling _EdScrollToSel( ). The example then repeats the operation for a selection made near the top of the file.

Visual FoxPro Code

SET LIBRARY TO EDSCTOSE
= TOSEL("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);

   _EdScrollToPos(wh, 0, TRUE);

   _EdGetEnv(wh, &EdEnv);
   _EdSelect(wh, EdEnv.length - 16, EdEnv.length);

   _PutStr("\nMade selection at end of file.");
   _Execute("WAIT WINDOW 'Press any key to scroll to selection.'");

   _EdScrollToSel(wh, TRUE);
   _EdSelect(wh, 1, 16);

   _PutStr("\nMade selection at beginning of file.");
   _Execute("WAIT WINDOW 'Press any key to scroll to selection.'");

   _EdScrollToSel(wh, TRUE);
}

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

See Also

_EdGetPos( ) API Library Routine | _EdSelect( ) API Library Routine | _EdSetPos( ) API Library Routine