84 |
} |
} |
85 |
|
|
86 |
|
|
87 |
|
enum { |
88 |
|
CDLG_FILE_OPEN = 0, |
89 |
|
CDLG_FILE_SAVE = 1 |
90 |
|
}; |
91 |
|
|
92 |
/* Use the common dialog to request a file from the user. |
/* Use the common dialog to request a file from the user. |
93 |
id can be either FILE_OPEN or FILE_SAVE. |
id can be either FILE_OPEN or FILE_SAVE. |
115 |
open.hwndOwner = hwnd; |
open.hwndOwner = hwnd; |
116 |
open.lpstrFile = file; |
open.lpstrFile = file; |
117 |
open.nMaxFile = sizeof (file) - 1; |
open.nMaxFile = sizeof (file) - 1; |
118 |
if (id == FILE_OPEN) |
if (id == CDLG_FILE_OPEN) |
119 |
open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST; |
open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST; |
120 |
else |
else |
121 |
open.Flags = OFN_OVERWRITEPROMPT; |
open.Flags = OFN_OVERWRITEPROMPT; |
122 |
|
|
123 |
if (id == FILE_OPEN && GetOpenFileName (&open)) |
if (id == CDLG_FILE_OPEN && GetOpenFileName (&open)) |
124 |
return open.lpstrFile; |
return open.lpstrFile; |
125 |
else if (id == FILE_SAVE && GetSaveFileName (&open)) |
else if (id == CDLG_FILE_SAVE && GetSaveFileName (&open)) |
126 |
return open.lpstrFile; |
return open.lpstrFile; |
127 |
|
|
128 |
return NULL; |
return NULL; |
132 |
get_filesave_dlg (HWND hwnd, const char *title, |
get_filesave_dlg (HWND hwnd, const char *title, |
133 |
const char *filter, const char *name) |
const char *filter, const char *name) |
134 |
{ |
{ |
135 |
return get_filename_dlg (hwnd, FILE_SAVE, title, filter, name); |
return get_filename_dlg (hwnd, CDLG_FILE_SAVE, title, filter, name); |
136 |
} |
} |
137 |
|
|
138 |
const char * |
const char * |
139 |
get_fileopen_dlg (HWND hwnd, const char *title, const char *filter, |
get_fileopen_dlg (HWND hwnd, const char *title, const char *filter, |
140 |
const char *name) |
const char *name) |
141 |
{ |
{ |
142 |
return get_filename_dlg (hwnd, FILE_OPEN, title, filter, name); |
return get_filename_dlg (hwnd, CDLG_FILE_OPEN, title, filter, name); |
143 |
} |
} |
144 |
|
|
145 |
|
|
318 |
} |
} |
319 |
|
|
320 |
|
|
321 |
/* Return the file size of the given file. */ |
/* Return the file size of the given file @fname. */ |
322 |
size_t |
DWORD |
323 |
get_file_size (const char *fname) |
get_file_size (const char *fname) |
324 |
{ |
{ |
325 |
size_t fsize; |
DWORD fsize; |
326 |
HANDLE fh; |
HANDLE fh; |
327 |
|
|
328 |
fh = CreateFile( fname, GENERIC_READ, FILE_SHARE_READ, |
fh = CreateFile (fname, GENERIC_READ, FILE_SHARE_READ, |
329 |
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); |
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
330 |
if( fh == INVALID_HANDLE_VALUE ) |
if (fh == INVALID_HANDLE_VALUE) |
331 |
return 0; |
return 0; |
332 |
fsize = GetFileSize( fh, NULL ); |
fsize = GetFileSize (fh, NULL); |
333 |
if( fsize == 0xFFFFFFFF ) |
if (fsize == 0xFFFFFFFF) |
334 |
fsize = 0; |
fsize = 0; |
335 |
CloseHandle( fh ); |
CloseHandle (fh); |
336 |
return fsize; |
return fsize; |
337 |
} /* get_file_size */ |
} |
338 |
|
|
339 |
|
|
340 |
int |
int |