_EdCloseFile( ) API Library Routine

JavaScript Editor js editor     Web development 



Main Page

Closes both the specified editing window and the file displaying in the window.

int _EdCloseFile(WHANDLE wh, int option)
WHANDLE wh;            /* Handle of editing window. */
int option;                  /* Closing options. */

Remarks

The option parameter can be one of the following:

Option parameter values

int result

0

Immediately save.

1

Save after dialog box confirmation.

2

Open Save As dialog box.

_EdCloseFile(В ) returns one of the following:

_EdCloseFile( ) return values

int meaning

1

Cancel without saving file.

0

Save and close file.

– 1

Discard changes and close file.

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 single file specified by a parameter, deletes a character, and closes the edit session three times. The first time, the routine calls _EdCloseFile(В ) with the "Immediately save" option, the second time with the "Save after dialog box" option, and the third time with the "Open Save As dialog box" option. Each time, the routine shows the return value of _EdCloseFile(В ).

Visual FoxPro Code

В Copy Code
SET LIBRARY TO EDCLOSE 
= EDCLOSE("x")

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 = 5;

   _PutValue(&val);
}

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

   WHANDLE wh;
   int retValue;

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

   // Open, delete a character, close "save without asking"
   wh = _EdOpenFile(pFILENAME, FO_READWRITE);

   _HUnLock(parm->p[0].val.ev_handle);

   _EdSelect(wh, 0, 1);
   _EdDelete(wh);
   retValue = _EdCloseFile(wh, 0); // save without asking
   _PutStr("\n_EdCloseFile() ="); putLong(retValue);

   // Open, delete a character, close "save with asking"
   _HLock(parm->p[0].val.ev_handle);
   wh = _EdOpenFile(pFILENAME, FO_READWRITE);
   _HUnLock(parm->p[0].val.ev_handle);

   _EdSelect(wh, 0, 1);
   _EdDelete(wh);
   retValue = _EdCloseFile(wh, 1); // save with asking
   _PutStr("\n_EdCloseFile() ="); putLong(retValue);

   // Open, delete a character, close "save as"
   _HLock(parm->p[0].val.ev_handle);
   wh = _EdOpenFile(pFILENAME, FO_READWRITE);
   _HUnLock(parm->p[0].val.ev_handle);

   _EdSelect(wh, 0, 1);
   _EdDelete(wh);
   retValue = _EdCloseFile(wh, 2); // save as
   _PutStr("\n_EdCloseFile() ="); putLong(retValue);
}

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

See Also



JavaScript Editor js editor     Web development