• Welcome to Jose's Read Only Forum 2023.
 

IFileOpenDialog Interface

Started by José Roca, September 08, 2011, 09:55:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
The following example demonstrates the use of the IFileOpenDialog interface, introduced in Windows Vista.


#COMPILE EXE
#DIM ALL
#INCLUDE "ShObjIdl.inc"

FUNCTION PBMAIN () AS LONG

   LOCAL hr AS LONG

   ' // Create an instance of the IFileOpenDialog interface
   LOCAL pofd AS IFileOpenDialog
   pofd = NEWCOM CLSID $CLSID_FileOpenDialog
   IF ISNOTHING(pofd) THEN EXIT FUNCTION

   DIM rgFileTypes(2) AS COMDLG_FILTERSPEC
   DIM pszNames(2) AS WSTRINGZ * %MAX_PATH
   DIM pszSpecs(2) AS WSTRINGZ * %MAX_PATH
   pszNames(0) = "PB code files"
   pszNames(1) = "Executable files"
   pszNames(2) = "All files"
   pszSpecs(0) = "*.bas;*.inc"
   pszSpecs(1) = "*.exe;*.dll"
   pszSpecs(2) = "*.*"
   rgFileTypes(0).pszName = VARPTR(pszNames(0)) : rgFileTypes(0).pszSpec = VARPTR(pszSpecs(0))
   rgFileTypes(1).pszName = VARPTR(pszNames(1)) : rgFileTypes(1).pszSpec = VARPTR(pszSpecs(1))
   rgFileTypes(2).pszName = VARPTR(pszNames(2)) : rgFileTypes(2).pszSpec = VARPTR(pszSpecs(2))
   hr = pofd.SetFileTypes(3, rgFileTypes(0))

   ' // Set the title of the dialog
   hr = pofd.SetTitle("A Single-Selection Dialog")

   ' // Display the dialog
   hr = pofd.Show(0)

   ' // Get the result
   LOCAL pItem AS IShellItem
   LOCAL pwszName AS WSTRINGZ PTR
   IF SUCCEEDED(hr) THEN
      hr = pofd.GetResult(pItem)
      IF SUCCEEDED(hr) THEN
         hr = pItem.GetDisplayName(%SIGDN_FILESYSPATH, pwszName)
         MSGBOX @pwszName
         CoTaskMemFree(pwszName)
      END IF
   END IF

END FUNCTION