forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Add support for Common Item Dialog

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Suggestions
View previous topic :: View next topic  
Author Message
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Sat Aug 23, 2014 8:13 am    Post subject: Add support for Common Item Dialog Reply with quote

It would be nice to have access to more modern looking file dialogs from FTN95. Using IFileDialog interface is not as complicated as it first seems and should give programs more consistent and modern look.

Below is a minimum example for a simple folder selection dialog in MiniBASIC syntax and sample project available here.
Code:

export GetFolder
func GetFolder(string title, string buffer)
   CoInitialize(NULL)
   IFileOpenDIalog *pfd = NULL
   HRESULT hr = CoCreateInstance(_CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, _IID_IFileOpenDialog, &pfd)
   if hr >= 0
      FILEOPENDIALOGOPTIONS options
      hr = pfd->GetOptions(&options)
      hr = pfd->SetOptions(options|FOS_PICKFOLDERS)
      hr = pfd->SetTitle(A2W(title))
      hr = pfd->Show(0)
      if hr >= 0
         IShellItem *psi
         wstring *pwszName
         hr = pfd->GetResult(&psi)
         if hr >= 0
            hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pwszName)
            buffer = W2A(#pwszName)
            CoTaskMemFree(pwszName)
            psi->Release()
         endif
      endif
      hr = pfd->Release()
   endif
   CoUninitialize()
endf
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Sat Aug 23, 2014 10:56 am    Post subject: Reply with quote

Thanks for the feedback. I will add this to the wish list.
Back to top
View user's profile Send private message AIM Address
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Sun Aug 24, 2014 7:54 am    Post subject: Reply with quote

I updated FTN95 sample project to support open/select file dialog.

Only difficulty was that SetFileTypes() method expects to get pointers to file filter information and only supports wide character arrays.
Code:

type wstr
   wstring str
endtype


type COMDLG_FILTERSPEC
   wstring *name
   wstring *spec
endtype


func count(string str), int
   int pos = instrr(str,",")
   int pos2 = len(str)
   int count = 0
   if len(str) > 0
      count += 1
      while pos
         count += 1
         pos2 = pos-1
         pos = instrr(pos-1, str, ",")
      endwhile
   endif

   return count
endf


export GetFile
func GetFile(string title, string buffer, string names, string specs)
   CoInitialize(NULL)

   ' Calculate required array dimensions
   int c = count(names)
   if count(specs) <> c
      buffer = ""
      return
   endif

   ' Allocate memory for the array of COMDLG_FILTERSPEC information
   COMDLG_FILTERSPEC *rgFileTypes = new(COMDLG_FILTERSPEC, c)
   ' Alllocate memory for the two arrays of wide character strings
   wstr *n = new(wstr, c)
   wstr *s = new(wstr, c)

   ' Next split the input character strings,
   ' convert to wide character strings and store into allocated arrays.
   ' Also need to set pointers in COMDLG_FILTERSPEC structure array to point
   ' into corresponding wide character array indices.
   int pos = instrr(names,",")
   int pos2 = len(names)
   int i = 0
   while pos
      #n[i].str = a2w(ltrim$(mid$(names,pos+1,pos2-pos)))
      i += 1
      pos2 = pos-1
      pos = instrr(pos-1,names,",")
   endwhile
   #n[i].str = a2w(ltrim$(mid$(names,pos+1,pos2-pos)))

   for i = 0 to c-1
      #rgFileTypes[c-1-i].name = #n[i].str
   next i

   pos = instrr(specs,",")
   pos2 = len(specs)
   i = 0
   while pos
      #s[i].str = a2w(ltrim$(mid$(specs,pos+1,pos2-pos)))
      i += 1
      pos2 = pos-1
      pos = instrr(pos-1,specs,",")
   endwhile
   #s[i].str = a2w(ltrim$(mid$(specs,pos+1,pos2-pos)))

   for i = 0 to c-1
      #rgFileTypes[c-1-i].spec = #s[i].str
   next i

   IFileOpenDIalog *pfd = NULL
   HRESULT hr = CoCreateInstance(_CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, _IID_IFileOpenDialog, &pfd)
   if hr >= 0
      hr = pfd->SetFileTypes(c,#rgFileTypes[0])
      hr = pfd->SetTitle(a2w(title)) ' Need to convert char to wchar
      hr = pfd->Show(0)
      if hr >= 0
         IShellItem *psi
         wstring *pwszName
         hr = pfd->GetResult(&psi)
         if hr >= 0
            hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pwszName)
            buffer = w2a(#pwszName) ' Convert from wchar to char and store into buffer
            CoTaskMemFree(pwszName)
            psi->Release()
         endif
      endif
      hr = pfd->Release()
   endif

   ' Delete allocated memory and cleanup
   delete n
   delete s
   delete rgFileTypes

   CoUninitialize()
endf
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Mon Aug 25, 2014 4:54 am    Post subject: Reply with quote

Does this address the file open dialogue problem that occurred with the introduction of Windows 7 ?
If it does, it would be a very welcome change.

There are numerous posts from around 2011 which addressed this problem, which I overcame by reducing the used memory to about 1.4gb for programs using the old windows file open dialogue that clearwin used.

John
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Suggestions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group