summaryrefslogtreecommitdiffstats
path: root/private/nw/convert/logview/fvopen.c
blob: 97a0458eb599113b8fa5708c502d1d93f370c4ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
  +-------------------------------------------------------------------------+
  |               MDI Text File View - File open Functions                  |
  +-------------------------------------------------------------------------+
  |                        (c) Copyright 1994                               |
  |                          Microsoft Corp.                                |
  |                        All rights reserved                              |
  |                                                                         |
  | Program               : [FVOpen.c]                                      |
  | Programmer            : Arthur Hanson                                   |
  | Original Program Date : [Feb 11, 1994]                                  |
  | Last Update           : [Feb 11, 1994]                                  |
  |                                                                         |
  | Version:  0.10                                                          |
  |                                                                         |
  | Description:                                                            |
  |                                                                         |
  | History:                                                                |
  |   arth  Jul 27, 1993    0.10    Original Version.                       |
  |                                                                         |
  +-------------------------------------------------------------------------+
*/

#include "LogView.h"
#include <fcntl.h>
#include <io.h>
#include <string.h>

#define MAXFILENAME 256


CHAR szPropertyName [] = "FILENAME";  // Name of the File name property list item


/////////////////////////////////////////////////////////////////////////
BOOL 
FileExists(
   PSTR pch
   )

/*++

Routine Description:


Arguments:


Return Value:


--*/

{
        int fh;

        if ((fh = _open(pch, O_RDONLY)) < 0)
             return(FALSE);

        _lclose(fh);
        return(TRUE);
} // FileExists


/////////////////////////////////////////////////////////////////////////
VOID APIENTRY 
GetFileName(
   HWND hwnd, 
   PSTR pstr
   )

/*++

Routine Description:


Arguments:


Return Value:


--*/

{
    CHAR szFmt[128];
    OPENFILENAME ofn;
    CHAR szFilterSpec[128];
    CHAR szDefExt[10];
    CHAR szFileName[MAXFILENAME];
    CHAR szFileTitle[MAXFILENAME];

    strcpy(szFileName, "");   // these need be NULL
    strcpy(szFileTitle, "");
    memset(&ofn,0,sizeof(ofn)) ;
    memset(szFilterSpec,0,sizeof(szFilterSpec)) ;

    LoadString (hInst, (WORD)IDS_OPENTEXT, 
                (LPSTR)szFmt, sizeof (szFmt));
    LoadString (hInst, (WORD)IDS_OPENFILTER,
                (LPSTR)szFilterSpec, sizeof (szFilterSpec));


    ofn.lStructSize       = sizeof(OPENFILENAME);
    ofn.hwndOwner         = hwnd;
    ofn.lpstrFilter       = szFilterSpec;
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter    = 0;
    ofn.nFilterIndex      = 0;
    ofn.lpstrFile         = szFileName;
    ofn.nMaxFile          = MAXFILENAME;
    ofn.lpstrInitialDir   = NULL;
    ofn.lpstrFileTitle    = szFileTitle;
    ofn.nMaxFileTitle     = MAXFILENAME;
    ofn.lpstrTitle        = szFmt;

    LoadString (hInst, (WORD)IDS_DEFEXT, (LPSTR)szDefExt, sizeof (szDefExt));
    ofn.lpstrDefExt       = szDefExt;
    ofn.Flags             = OFN_FILEMUSTEXIST;
    
    // Use standard open dialog
    if (!GetOpenFileName ((LPOPENFILENAME)&ofn)) {
        *pstr = 0;
    }
    else {
        strcpy(pstr, ofn.lpstrFile);
    }
 
   return;

} // GetFileName