Mercurial > dwindows
comparison win/dw.c @ 1294:4bc8b6ffbe1e
Code changes to enable default filename on Windows with dw_file_browse().
Also added an example in the test program.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 01 Nov 2011 10:21:48 +0000 |
parents | 0712ee0f311e |
children | b8f6e7dd4544 |
comparison
equal
deleted
inserted
replaced
1293:0712ee0f311e | 1294:4bc8b6ffbe1e |
---|---|
10145 #else | 10145 #else |
10146 env->DWSubVersion = DW_SUB_VERSION; | 10146 env->DWSubVersion = DW_SUB_VERSION; |
10147 #endif | 10147 #endif |
10148 } | 10148 } |
10149 | 10149 |
10150 /* Helper to make sure all /s are \s */ | |
10151 void _to_dos(char *dst, char *src) | |
10152 { | |
10153 int x = 0; | |
10154 | |
10155 while(src[x]) | |
10156 { | |
10157 if(src[x] == '/') | |
10158 dst[x] = '\\'; | |
10159 else | |
10160 dst[x] = src[x]; | |
10161 x++; | |
10162 } | |
10163 dst[x] = 0; | |
10164 } | |
10165 | |
10150 /* | 10166 /* |
10151 * Opens a file dialog and queries user selection. | 10167 * Opens a file dialog and queries user selection. |
10152 * Parameters: | 10168 * Parameters: |
10153 * title: Title bar text for dialog. | 10169 * title: Title bar text for dialog. |
10154 * defpath: The default path of the open dialog. | 10170 * defpath: The default path of the open dialog. |
10212 } | 10228 } |
10213 #endif | 10229 #endif |
10214 } | 10230 } |
10215 else | 10231 else |
10216 { | 10232 { |
10233 DWORD att = defpath ? GetFileAttributes(defpath) : INVALID_FILE_ATTRIBUTES; | |
10234 | |
10217 if (ext) | 10235 if (ext) |
10218 { | 10236 { |
10219 /* | 10237 /* |
10220 * The following mess is because sprintf() trunates at first \0 | 10238 * The following mess is because sprintf() trunates at first \0 |
10221 * and format of filter is eg: "c files (*.c)\0*.c\0All Files\0*.*\0\0" | 10239 * and format of filter is eg: "c files (*.c)\0*.c\0All Files\0*.*\0\0" |
10235 memset( &of, 0, sizeof(OPENFILENAME) ); | 10253 memset( &of, 0, sizeof(OPENFILENAME) ); |
10236 | 10254 |
10237 of.lStructSize = sizeof(OPENFILENAME); | 10255 of.lStructSize = sizeof(OPENFILENAME); |
10238 of.hwndOwner = HWND_DESKTOP; | 10256 of.hwndOwner = HWND_DESKTOP; |
10239 of.hInstance = DWInstance; | 10257 of.hInstance = DWInstance; |
10240 of.lpstrInitialDir = defpath; | |
10241 of.lpstrTitle = title; | 10258 of.lpstrTitle = title; |
10259 if(att != INVALID_FILE_ATTRIBUTES && (att & FILE_ATTRIBUTE_DIRECTORY)) | |
10260 of.lpstrInitialDir = defpath; | |
10261 else if(defpath) | |
10262 _to_dos(filenamebuf, defpath); | |
10242 of.lpstrFile = filenamebuf; | 10263 of.lpstrFile = filenamebuf; |
10243 of.lpstrFilter = filterbuf; | 10264 of.lpstrFilter = filterbuf; |
10244 of.nFilterIndex = 1; | 10265 of.nFilterIndex = 1; |
10245 of.nMaxFile = 1000; | 10266 of.nMaxFile = 1000; |
10246 //of.lpstrDefExt = ext; | 10267 /*of.lpstrDefExt = ext;*/ |
10247 of.Flags = OFN_NOCHANGEDIR; | 10268 of.Flags = OFN_NOCHANGEDIR; |
10248 | 10269 |
10249 if (flags & DW_FILE_SAVE) | 10270 if (flags & DW_FILE_SAVE) |
10250 { | 10271 { |
10251 of.Flags |= OFN_OVERWRITEPROMPT; | 10272 of.Flags |= OFN_OVERWRITEPROMPT; |