Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

PB/DLL, Open multiple files..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PB/DLL, Open multiple files..

    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Simple sample of how to get multiple file names via Open file dialog.
    ' Public Domain by Borje Hagsten. As always, use at own risk.. :-)
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    #INCLUDE "COMDLG32.INC"
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Custom-made OpenFileDialog function, with additional space for multiple files.
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION OpenFilesDialog(BYVAL hWnd AS LONG, _                ' parent window
                             BYVAL Caption AS STRING, _           ' caption
                             Filespec AS STRING, _                ' filename (input/output)
                             BYVAL InitialDir AS STRING, _        ' start directory
                             BYVAL Filter AS STRING, _            ' filename filter
                             BYVAL DefExtension AS STRING, _      ' default extension
                             Flags AS DWORD) AS LONG              ' flags
     
      LOCAL sFile         AS STRING
     
      LOCAL Ofn           AS OPENFILENAME
      LOCAL zFileTitle    AS ASCIIZ * 256
      LOCAL zFilter       AS ASCIIZ * 256
      LOCAL zInitialDir   AS ASCIIZ * 256
      LOCAL zTitle        AS ASCIIZ * 256
      LOCAL zDefExt       AS ASCIIZ * 10
     
      REPLACE "|" WITH CHR$(0) IN Filter
     
      IF LEN(InitialDir) = 0 THEN
        InitialDir = CURDIR$
      END IF
     
      zFilter     = Filter + CHR$(0)
      zInitialDir = InitialDir + CHR$(0)
     
      sFile = STRING$(16383, 0)  '<- PLENTY OF ROOM FOR MULTIPLE FILES
      MID$(sFile,1) = FileSpec
     
      zDefExt     = DefExtension + CHR$(0)
      zTitle      = Caption + CHR$(0)
     
      ofn.lStructSize       = SIZEOF(ofn)
      ofn.hWndOwner         = hWnd
      ofn.lpstrFilter       = VARPTR(zFilter)
      ofn.nFilterIndex      = 1
      ofn.lpstrFile         = STRPTR(sFile)
      ofn.nMaxFile          = LEN(sFile)
      ofn.lpstrFileTitle    = VARPTR(zFileTitle)
      ofn.nMaxFileTitle     = SIZEOF(zFileTitle)
      ofn.lpstrInitialDir   = VARPTR(zInitialDir)
      IF LEN(zTitle) THEN
        ofn.lpstrTitle      = VARPTR(zTitle)
      END IF
      ofn.Flags             = Flags
      ofn.lpstrDefExt       = VARPTR(zDefExt)
     
      FUNCTION = GetOpenFilename(ofn)
     
      Filespec = RTRIM$(sFile,CHR$(0))
      Flags    = ofn.Flags
     
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Get multiple files via Open file dialog
    ' Note, when multiple files are selected, first part contains path,
    ' rest of returned string contains the file names.
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION GetMultipleFiles(BYVAL hWnd AS LONG, BYVAL sPath AS STRING) AS LONG
      LOCAL sFileName AS STRING, sFile AS STRING, lStyle AS DWORD, I AS LONG, fCount AS LONG
     
      sFileName = "*.*" 'whatever
      lStyle = %OFN_ALLOWMULTISELECT OR %OFN_EXPLORER OR %OFN_ENABLESIZING OR _
               %OFN_FILEMUSTEXIST OR %OFN_NODEREFERENCELINKS OR %OFN_HIDEREADONLY
     
      IF OpenFilesDialog(hWnd, "Add file(s)", _
                            sFileName, sPath, _
                            "All Files  (*.*)|*.*|Data files  (*.DAT, *.INI)|*.DAT;*.INI|System files  (*.EXE, *.DLL)|*.EXE;*.DLL|Text files  (*.DIZ, *.TXT)|*.DIZ;*.TXT|", _
                            "", lStyle) THEN
     
         fCount = PARSECOUNT(sFileName, CHR$(0))
         LISTBOX RESET hWnd, 20
     
         IF fCount = 1 THEN                          '<- one file selected
            sFile = PARSE$(sFileName, CHR$(0), 1)    '<- Full path and file name
            LISTBOX ADD hWnd, 20, sFile              '<- add to list, to see what we got
            
         ELSE                                        '<- Several files selected
            sPath = PARSE$(sFileName, CHR$(0), 1)    '<- Path first
            IF RIGHT$(sPath, 1) <> "\" THEN sPath = sPath & "\"
            FOR I = 2 TO fCount
               sFile = PARSE$(sFileName, CHR$(0), I) '<- File names
               LISTBOX ADD hWnd, 20, sPath + sFile   '<- together for full path and file name
            NEXT
            DECR fCount 'adjust fCount before we return it
        END IF
      END IF
      
      FUNCTION = fCount 'return count, if we ever should need it
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main callback
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc() AS LONG
      SELECT CASE CBMSG
         CASE %WM_COMMAND
            SELECT CASE CBCTL
               CASE 1  : DIALOG END CBHNDL, 1                   '<- exit
               CASE 10 : CALL GetMultipleFiles(CBHNDL, CURDIR$) '<-get files
            END SELECT
      END SELECT
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG
     
      DIALOG NEW 0, "Open multiple files test ",,, 200, 120, %WS_SYSMENU, 0 TO hDlg
     
      CONTROL ADD LISTBOX, hDlg, 20, ,              5,  5, 185, 90
      CONTROL ADD BUTTON,  hDlg, 10, "Get files",  40, 86,  60, 14, 1
      CONTROL ADD BUTTON,  hDlg,  1, "E&xit",     100, 86,  60, 14, 1
     
      DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION

    ------------------
Working...
X