comparison win/dw.c @ 628:7d93356f250a

Fixed dw_file_browse(); filters now work on extension passed in.
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 12 Apr 2008 12:22:09 +0000
parents 4d1d9aeb0bbc
children 6e84e055d981
comparison
equal deleted inserted replaced
627:77cc62375fee 628:7d93356f250a
9120 */ 9120 */
9121 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) 9121 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags)
9122 { 9122 {
9123 OPENFILENAME of; 9123 OPENFILENAME of;
9124 char filenamebuf[1001] = ""; 9124 char filenamebuf[1001] = "";
9125 char filterbuf[1000] = "";
9125 int rc; 9126 int rc;
9126 9127
9127 BROWSEINFO bi; 9128 BROWSEINFO bi;
9128 TCHAR szDir[MAX_PATH]; 9129 TCHAR szDir[MAX_PATH];
9129 LPITEMIDLIST pidl; 9130 LPITEMIDLIST pidl;
9156 } 9157 }
9157 } 9158 }
9158 } 9159 }
9159 else 9160 else
9160 { 9161 {
9161 if(ext) 9162 if (ext)
9162 { 9163 {
9163 strcpy(filenamebuf, "*."); 9164 /*
9164 strcat(filenamebuf, ext); 9165 * The following mess is because sprintf() trunates at first \0
9165 } 9166 * and format of filter is eg: "c files (*.c)\0*.c\0All Files\0*.*\0\0"
9166 9167 */
9167 memset(&of, 0, sizeof(OPENFILENAME)); 9168 int len;
9169 char *ptr = filterbuf;
9170 memset( filterbuf, 0, sizeof(filterbuf) );
9171 len = sprintf( ptr, "%s Files (*.%s)", ext, ext );
9172 ptr = ptr + len + 1; // past first \0
9173 len = sprintf( ptr, "*.%s", ext );
9174 ptr = ptr + len + 1; // past next \0
9175 len = sprintf( ptr, "All Files" );
9176 ptr = ptr + len + 1; // past next \0
9177 len = sprintf( ptr, "*.*" );
9178 }
9179
9180 memset( &of, 0, sizeof(OPENFILENAME) );
9168 9181
9169 of.lStructSize = sizeof(OPENFILENAME); 9182 of.lStructSize = sizeof(OPENFILENAME);
9170 of.hwndOwner = HWND_DESKTOP; 9183 of.hwndOwner = HWND_DESKTOP;
9171 of.hInstance = DWInstance; 9184 of.hInstance = DWInstance;
9172 of.lpstrInitialDir = defpath; 9185 of.lpstrInitialDir = defpath;
9173 of.lpstrTitle = title; 9186 of.lpstrTitle = title;
9174 of.lpstrFile = filenamebuf; 9187 of.lpstrFile = filenamebuf;
9188 of.lpstrFilter = filterbuf;
9189 of.nFilterIndex = 1;
9175 of.nMaxFile = 1000; 9190 of.nMaxFile = 1000;
9176 of.lpstrDefExt = ext; 9191 //of.lpstrDefExt = ext;
9177 of.Flags = 0; 9192 of.Flags = OFN_NOCHANGEDIR;
9178 9193
9179 if(flags & DW_FILE_SAVE) 9194 if (flags & DW_FILE_SAVE)
9195 {
9196 of.Flags |= OFN_OVERWRITEPROMPT;
9180 rc = GetSaveFileName(&of); 9197 rc = GetSaveFileName(&of);
9198 }
9181 else 9199 else
9200 {
9201 of.Flags |= OFN_FILEMUSTEXIST;
9182 rc = GetOpenFileName(&of); 9202 rc = GetOpenFileName(&of);
9183 9203 }
9184 if(rc) 9204
9205 if (rc)
9185 return strdup(of.lpstrFile); 9206 return strdup(of.lpstrFile);
9186 } 9207 }
9187 return NULL; 9208 return NULL;
9188 } 9209 }
9189 9210