Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1530 dpurdie 1
#ifndef _BRWSDLG_RUL_
2
#define _BRWSDLG_RUL_
3
 
4
#include "FileBrowseDlg.h"
5
 
6
prototype Kernel32.RtlMoveMemory(BYREF STRING, POINTER, NUMBER);
7
 
8
typedef STR260
9
begin
10
   STRING sz[260];
11
end;
12
 
13
///////////////////////////////////////////////////////////////////////////////
14
//
15
// FileBrowseDlg() uses the Windows GetFileNameA function to allow single file
16
// selection. Callers specify filter, dialog title, and initial browse
17
// directory.  SEE END OF FILE FOR EXAMPLE ON HOW TO USE
18
//
19
// Inputs:
20
//
21
// szFile: String variable into which FileBrowseDlg() will place the selected
22
//      file's fully qualified pathname. The variable passed in as szFile can
23
//      be dynamically sized.  szFile is passed by reference.
24
//
25
//  szFilter: Filter spec for dialog. In the form "<descr>|<ext>||". For example:
26
//
27
//     "Text files (*.txt)|*.txt|All files (*.*)|*.*||"
28
//
29
//      The description ("Text files (*.txt)" above) must be separated from
30
//      the extension ("*.txt" above) by a pipe "|" character. The entire
31
//      string must end in a double || ("||").
32
//
33
//  szDialogTitle: A string containig the title to display on the file
34
//      browse dialog.
35
//
36
//  szInitialDir: A string specifying the directory the browse dialog
37
//      initially opens to.
38
//
39
//  bMultiSel: Set to TRUE if you wish to enable multiple selection.
40
//
41
//  listFiles: List that will be loaded with directory and filenames if
42
//      multiple selection is enabled (i.e. bMultiSel = TRUE).
43
//      List is passed by reference (by default, since list variables
44
//      are pointers).
45
//
46
//  bDerefLinks: Set to TRUE if you want to dereference shell links (also
47
//      known as shortcuts). If TRUE, then choosing a shell link causes
48
//      it to be dereferenced by the shell.
49
//
50
// Returns:
51
//
52
//      Returns 0 when a file is successfully selected. Returns less than
53
//      zero when when the user cancels/closes the browse dialog or an
54
//      error occurs. If an error occurs, a message box displays the error
55
//      identifier.
56
//
57
// History:
58
//
59
//      03-12-99 RBS Updated this header to correctly document bDerefLinks.
60
//      06-01-01 RBS Merged in changes from latest on InstallShield's site.
61
//
62
///////////////////////////////////////////////////////////////////////////////
63
 
64
function FileBrowseDlg( szFile, szFilter, szDialogTitle, szInitialDir,
65
                        bMultiSel, listFiles, bDerefLinks)
66
 
67
    OPENFILENAME ofn;
68
    STRING szMsg, szFileTitle[260];
69
    STRING szCustomFilter[260], szTemp[260];
70
    LONG   nLen, nCount, nResult, n, nFlags, nErr;
71
    STR260 str;
72
 
73
begin
74
 
75
    // Replace each '|' character in szFilter with '\0' since that is
76
    // what is required by the Win32 API.
77
    nLen = StrLength( szFilter );
78
    nLen = nLen - 1;
79
    nCount = 0;
80
    for nCount = 0 to nLen
81
        if ( szFilter[nCount] = '|' ) then
82
            szFilter[nCount] = '\0';
83
        endif;
84
    endfor;
85
 
86
    UseDLL(WINSYSDIR ^ "comdlg32.dll");
87
 
88
    nFlags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY
89
             | OFN_NOCHANGEDIR | OFN_EXPLORER;
90
    if bMultiSel then
91
        nFlags = nFlags | OFN_ALLOWMULTISELECT;
92
    endif;
93
    if bDerefLinks = FALSE then
94
        nFlags = nFlags | OFN_NODEREFERENCELINKS;
95
    endif;
96
 
97
    nResult = GetWindowHandle(HWND_INSTALL);
98
 
99
    ofn.lStructSize = SizeOf(ofn);
100
    ofn.hwndOwner = nResult;
101
 
102
    // The string pointed to by ofn.lpstrFile is modified by
103
    // GetOpenFileName. The only way to have a string in
104
    // script to reflect the change is to point lpstrFile
105
    // to a structure that contains just a string member.
106
    str.sz = szFile;
107
    ofn.lpstrFile = &str;
108
    ofn.nMaxFile = SizeOf(str);
109
 
110
    // Notice how the address of an explicitly sized string
111
    // is used when assigning to a member who was declared
112
    // as a LONG string pointer (lpstr). For example, &szFilter.
113
    ofn.lpstrFilter = &szFilter;
114
    ofn.nFilterIndex = 1;
115
    ofn.lpstrFileTitle = &szFileTitle;
116
    ofn.nMaxFileTitle = 260;
117
    ofn.lpstrTitle = &szDialogTitle;
118
    ofn.Flags = nFlags;
119
    ofn.lpstrDefExt = &szTemp;
120
    ofn.lpstrInitialDir = &szInitialDir;
121
    ofn.hInstance = 0;
122
    ofn.lpstrCustomFilter = &szCustomFilter;
123
    ofn.nMaxCustFilter = 260;
124
    ofn.lpfnHook = 0;
125
 
126
    nResult = GetOpenFileNameA(&ofn);
127
    if nResult = 1 then     
128
        if bMultiSel then
129
            // A direct assignment in the form of szFile = str.sz
130
            // will result in all data beyond the first null to be
131
            // lost. This only happend when the string is assigned
132
            // with a structure member. This is the reason why a
133
            // very indirect method is being used the transfer the
134
            // contents of str.sz to szFile.
135
            Resize( szFile, SizeOf(str));
136
            RtlMoveMemory( szFile, &str, SizeOf(str));
137
            StrGetTokens( listFiles, szFile, "");
138
        else
139
            szFile = str.sz;
140
        endif;
141
    else
142
        // We had an error in GetOpenFileNameA() so get the error string.
143
        nErr = CommDlgExtendedError();
144
        switch (nErr)
145
            case CDERR_DIALOGFAILURE: szMsg = CDERR_DIALOGFAILURE_MSG;
146
            case CDERR_FINDRESFAILURE: szMsg = CDERR_FINDRESFAILURE_MSG;
147
            case CDERR_INITIALIZATION: szMsg = CDERR_INITIALIZATION_MSG;
148
            case CDERR_LOADRESFAILURE: szMsg = CDERR_LOADRESFAILURE_MSG;
149
            case CDERR_LOADSTRFAILURE: szMsg = CDERR_LOADSTRFAILURE_MSG;
150
            case CDERR_LOCKRESFAILURE: szMsg = CDERR_LOCKRESFAILURE_MSG;
151
            case CDERR_MEMALLOCFAILURE: szMsg = CDERR_MEMALLOCFAILURE_MSG;
152
            case CDERR_MEMLOCKFAILURE: szMsg = CDERR_MEMLOCKFAILURE_MSG;
153
            case CDERR_NOHINSTANCE: szMsg = CDERR_NOHINSTANCE_MSG;
154
            case CDERR_NOHOOK: szMsg = CDERR_NOHOOK_MSG;
155
            case CDERR_NOTEMPLATE: szMsg = CDERR_NOTEMPLATE_MSG;
156
            case CDERR_REGISTERMSGFAIL: szMsg = CDERR_REGISTERMSGFAIL_MSG;
157
            case CDERR_STRUCTSIZE: szMsg = CDERR_STRUCTSIZE_MSG;
158
            case FNERR_BUFFERTOOSMALL: szMsg = FNERR_BUFFERTOOSMALL_MSG;
159
            case FNERR_INVALIDFILENAME: szMsg = FNERR_INVALIDFILENAME_MSG;
160
            case FNERR_SUBCLASSFAILURE: szMsg = FNERR_SUBCLASSFAILURE_MSG;
161
        endswitch;
162
        if nErr != 0 then
163
            // User did not close or cancel dialog box.
164
            MessageBox("FileBrowseDlg() error:\n\n" + szMsg, SEVERE);
165
        endif;
166
        return -1;
167
    endif;
168
 
169
    UnUseDLL(WINSYSDIR ^ "comdlg32.dll");
170
 
171
    return 0;   
172
end;
173
 
174
///////////////////////////////////////////////////////////////////////////////
175
// //Need declarations for FileBrowseDlg and friends.
176
// #include "brwsdlg.h"
177
//
178
// STRING szFile, svFileList, svTemp, szFilter;
179
// NUMBER nResult, nReturn;
180
// BOOL   bMultiSel, bDerefLinks;
181
// LIST   listFiles;
182
//
183
//  // If I want to support multiple selection, set bMultiSel to TRUE
184
//  // and pass in a valid string list.
185
//  bMultiSel = TRUE;
186
//  bDerefLinks = FALSE;
187
//  listFiles = ListCreate(STRINGLIST);
188
//  szFilter = "Text files (*.txt)|*.txt|All files (*.*)|*.*||";
189
//  
190
//  // Open the file browse dialog.
191
//  nResult = FileBrowseDlg( szFile,
192
//                           szFilter,
193
//                           "Select the DCOM98.EXE File",
194
//                           "c:\\",
195
//                           bMultiSel,
196
//                           listFiles,
197
//                           bDerefLinks );
198
//  if nResult = 0 then
199
//      if bMultiSel then
200
//          // If I chose multiple selection, I must parse the info, which is stored
201
//          // in list. First item will be dir, all others are individual filenames.
202
//          nReturn = ListGetFirstString(listFiles, svTemp);
203
//          while nReturn != END_OF_LIST
204
//              svFileList = svFileList + svTemp + "\n";
205
//              nReturn = ListGetNextString(listFiles, svTemp);
206
//          endwhile;
207
//          MessageBox("Directory (first item) and selected files:\n\n" + svFileList, 0);
208
//      else
209
//          // No multiple selection, so a single file/path was set.
210
//          MessageBox("Selected file:\n\n" + szFile, 0);
211
//      endif;
212
//  endif;
213
//  
214
//  ListDestroy(listFiles);
215
///////////////////////////////////////////////////////////////////////////////
216
 
217
 
218
 
219
 
220
#endif