Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
popfile.c File Reference
#include <windows.h>
#include <commdlg.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

void PopFileInitialize (HWND hwnd)
BOOL PopFileOpenDlg (HWND hwnd, LPSTR lpstrFileName, LPSTR lpstrTitleName)
BOOL PopFileSaveDlg (HWND hwnd, LPSTR lpstrFileName, LPSTR lpstrTitleName)
static long PopFileLength (int hFile)
BOOL PopFileRead (HWND hwndEdit, LPSTR lpstrFileName)
BOOL PopFileWrite (HWND hwndEdit, LPSTR lpstrFileName)

Variables

static OPENFILENAME ofn

Function Documentation

Definition at line 49 of file popfile.c.

     {
     static char *szFilter[] = { "Text Files (*.TXT)",  "*.txt",
                                 "ASCII Files (*.ASC)", "*.asc",
                                 "All Files (*.*)",     "*.*",
                                 "" } ;

     ofn.lStructSize       = sizeof (OPENFILENAME) ;
     ofn.hwndOwner         = hwnd ;
     ofn.hInstance         = NULL ;
     ofn.lpstrFilter       = szFilter [0] ;
     ofn.lpstrCustomFilter = NULL ;
     ofn.nMaxCustFilter    = 0 ;
     ofn.nFilterIndex      = 0 ;
     ofn.lpstrFile         = NULL ;          // Set in Open and Close functions
     ofn.nMaxFile          = _MAX_PATH ;
     ofn.lpstrFileTitle    = NULL ;          // Set in Open and Close functions
     ofn.nMaxFileTitle     = _MAX_FNAME + _MAX_EXT ;
     ofn.lpstrInitialDir   = NULL ;
     ofn.lpstrTitle        = NULL ;
     ofn.Flags             = 0 ;             // Set in Open and Close functions
     ofn.nFileOffset       = 0 ;
     ofn.nFileExtension    = 0 ;
     ofn.lpstrDefExt       = "txt" ;
     ofn.lCustData         = 0L ;
     ofn.lpfnHook          = NULL ;
     ofn.lpTemplateName    = NULL ;
     }

Here is the caller graph for this function:

static long PopFileLength ( int  hFile) [static]

Definition at line 98 of file popfile.c.

     {
     long lCurrentPos = _llseek (hFile, 0L, 1) ;
     long lFileLength = _llseek (hFile, 0L, 2) ;
     
     _llseek (hFile, lCurrentPos, 0) ;

     return lFileLength ;
     }

Here is the caller graph for this function:

BOOL PopFileOpenDlg ( HWND  hwnd,
LPSTR  lpstrFileName,
LPSTR  lpstrTitleName 
)

Definition at line 78 of file popfile.c.

     {
     ofn.hwndOwner         = hwnd ;
     ofn.lpstrFile         = lpstrFileName ;
     ofn.lpstrFileTitle    = lpstrTitleName ;
     ofn.Flags             = OFN_CREATEPROMPT ;

     return GetOpenFileName (&ofn) ;
     }

Here is the caller graph for this function:

BOOL PopFileRead ( HWND  hwndEdit,
LPSTR  lpstrFileName 
)

Definition at line 108 of file popfile.c.

     {
     long   lLength ;
     HANDLE hBuffer ;
     int    hFile ;
     LPSTR  lpstrBuffer ;

     if (-1 == (hFile = _lopen (lpstrFileName, OF_READ | OF_SHARE_DENY_WRITE)))
          return FALSE ;

     if ((lLength = PopFileLength (hFile)) >= 32000)
          {
          _lclose (hFile) ;
          return FALSE ;
          }

     if (NULL == (hBuffer = GlobalAlloc (GHND, lLength + 1)))
          {
          _lclose (hFile) ;
          return FALSE ;
          }

     lpstrBuffer = GlobalLock (hBuffer) ;
     _lread (hFile, lpstrBuffer, (WORD) lLength) ;
     _lclose (hFile) ;
     lpstrBuffer [(WORD) lLength] = '\0' ;

     SetWindowText (hwndEdit, lpstrBuffer) ;
     GlobalUnlock (hBuffer) ;
     GlobalFree (hBuffer) ;

     return TRUE ;
     }

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL PopFileSaveDlg ( HWND  hwnd,
LPSTR  lpstrFileName,
LPSTR  lpstrTitleName 
)

Definition at line 88 of file popfile.c.

     {
     ofn.hwndOwner         = hwnd ;
     ofn.lpstrFile         = lpstrFileName ;
     ofn.lpstrFileTitle    = lpstrTitleName ;
     ofn.Flags             = OFN_OVERWRITEPROMPT ;

     return GetSaveFileName (&ofn) ;
     }

Here is the caller graph for this function:

BOOL PopFileWrite ( HWND  hwndEdit,
LPSTR  lpstrFileName 
)

Definition at line 142 of file popfile.c.

     {
     HANDLE hBuffer ;
     int    hFile ;
     LPSTR  lpstrBuffer ;
     WORD   wLength ;

     if (-1 == (hFile = _lopen (lpstrFileName, OF_WRITE | OF_SHARE_EXCLUSIVE)))
          if (-1 == (hFile = _lcreat (lpstrFileName, 0)))
               return FALSE ;

     wLength = GetWindowTextLength (hwndEdit) ;
     hBuffer = (HANDLE) SendMessage (hwndEdit, EM_GETHANDLE, 0, 0L) ;
     lpstrBuffer = (LPSTR) LocalLock (hBuffer) ;

     if (wLength != _lwrite (hFile, lpstrBuffer, wLength))
          {
          _lclose (hFile) ;
          return FALSE ;
          }

     _lclose (hFile) ;
     LocalUnlock (hBuffer) ;

     return TRUE ;
     }

Here is the caller graph for this function:


Variable Documentation

OPENFILENAME ofn [static]

Definition at line 47 of file popfile.c.