PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: John Montenigro on February 02, 2011, 01:22:16 PM

Title: Questions about FF_SaveFileDialog() - how to limit user selections
Post by: John Montenigro on February 02, 2011, 01:22:16 PM
When I run the following Function, I noticed something undesireable, and I don't know if it's a problem with my code, the way FF works, or the way Windows works... I'd appreciate a critical look at the code and a good slap alongside the head, as necessary...

In the target file folder, we have files "tiny1.ics" and "tiny1.csv". Let's say that my user has already selected to write an ICS file. When the dialog appears, only the files with the indicated extension are shown. (Mouse selection is no problem.) But when he starts to type: T I N ...
That's when the SaveFileDialog() shows BOTH the .CSV as well as the .ICS,  and because C comes before I in the alphabet, the typing is defaulting to .CSV!!! If he doesn't see the different extension, we've got trouble!!!

I read the FF help, and read info in the SDK to the referenced OpenFileName call, but I don't see any flags that would help...

How do I prevent the Dialog from showing files with extensions that I do NOT want the user to select?

Thanks,
-John


Function FRMMAIN_CMDSAVE2FILE_BN_CLICKED ( _
                                         ControlIndex     As Long,  _  ' index in Control Array
                                         hWndForm         As Dword, _  ' handle of Form
                                         hWndControl      As Dword, _  ' handle of Control
                                         idButtonControl  As Long   _  ' identifier of button
                                         ) As Long
   Local TheText As String 

   TheText = PrepForCopy 
' pops up a panel with options for different file formats, then creates a string from the data in a UDT

   If UCase$(Left$(TheText, 4)) = "EXIT" Then Exit Function
     
   '----------------------------------------------
   'these are for the SaveFile dialog:
   Local nResult     As Long      ' determines whether the OpenFiles dialog was cancelled
   Local sFilename   As String    ' holds the returned list of selected file(s)
   Local sFilter     As String    ' holds the filter list   
   Local nFlags      As Long      ' flags that descibe the OpenFiles dialog behavior
   Local sDefExt     As String    ' in case user doesn't type the EXT
   '
   If gFileTypeFlag = %FileTypeiCal Then
      sFilter = "Calendar files (*.ics)|*.ics|All files (*.*)|*.*"
      sDefExt = "ics"         
   ElseIf gFileTypeFlag = %FileTypeCSV Then
      sFilter = "Comma-delimited files (*.csv)|*.csv|All files (*.*)|*.*"
      sDefExt = "csv"         
   Else
      sFilter = "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc|All files (*.*)|*.*"     
      sDefExt = "txt"
   End If
? "sDefExt = " & sDefExt,,"sDefExt"   ' only for development/testing
   
   nFlags  = %OFN_HIDEREADONLY Or %OFN_LONGNAMES Or %OFN_OVERWRITEPROMPT Or %OFN_EXPLORER     
   nResult = FF_SaveFileDialog( hWndForm, "Save File As", sFilename, "", sFilter, sDefExt, nFlags, %True)
   
'>>>>>>>> Somethings wrong: although I have set a default extension, the dialog is finding and "suggesting" a file with a different extension!   
         
   'see if the dialog was cancelled
   If nResult = 0 Then Exit Function  'leave as is! even though it's tempting to restructure the exit...
'? "nResult: " & Str$(nResult) ,,"post dialog"
   '----------------------------------------------
   
   'write the file...   
   Call WriteToFile(sFilename, TheText)
   
End Function