diff 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
line wrap: on
line diff
--- a/win/dw.c	Tue Nov 01 06:01:26 2011 +0000
+++ b/win/dw.c	Tue Nov 01 10:21:48 2011 +0000
@@ -10147,6 +10147,22 @@
 #endif
 }
 
+/* Helper to make sure all /s are \s */
+void _to_dos(char *dst, char *src)
+{
+   int x = 0;
+   
+   while(src[x])
+   {
+      if(src[x] == '/')
+         dst[x] = '\\';
+      else
+         dst[x] = src[x];
+      x++;
+   }
+   dst[x] = 0;
+}
+
 /*
  * Opens a file dialog and queries user selection.
  * Parameters:
@@ -10214,6 +10230,8 @@
    }
    else
    {
+      DWORD att = defpath ? GetFileAttributes(defpath) : INVALID_FILE_ATTRIBUTES;
+      
       if (ext)
       {
          /*
@@ -10237,13 +10255,16 @@
       of.lStructSize = sizeof(OPENFILENAME);
       of.hwndOwner = HWND_DESKTOP;
       of.hInstance = DWInstance;
-      of.lpstrInitialDir = defpath;
       of.lpstrTitle = title;
+      if(att != INVALID_FILE_ATTRIBUTES && (att & FILE_ATTRIBUTE_DIRECTORY))
+        of.lpstrInitialDir = defpath;
+      else if(defpath)
+        _to_dos(filenamebuf, defpath);
       of.lpstrFile = filenamebuf;
       of.lpstrFilter = filterbuf;
       of.nFilterIndex = 1;
       of.nMaxFile = 1000;
-      //of.lpstrDefExt = ext;
+      /*of.lpstrDefExt = ext;*/
       of.Flags = OFN_NOCHANGEDIR;
 
       if (flags & DW_FILE_SAVE)