Dialog Ulo₧it soubor

Postup:
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
    "GetSaveFileNameA" (pOpenfilename As OpenFilename) As Long

Private Type OpenFilename
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    iFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Private Enum OFNFlagsEnum
    OFN_ALLOWMULTISELECT = &H200
    OFN_CREATEPROMPT = &H2000
    OFN_ENABLEHOOK = &H20
    OFN_ENABLETEMPLATE = &H40
    OFN_ENABLETEMPLATEHANDLE = &H80
    OFN_EXPLORER = &H80000
    OFN_EXTENSIONDIFFERENT = &H400
    OFN_FILEMUSTEXIST = &H1000
    OFN_HIDEREADONLY = &H4
    OFN_LONGNAMES = &H200000
    OFN_NOCHANGEDIR = &H8
    OFN_NODEREFERENCELINKS = &H100000
    OFN_NOLONGNAMES = &H40000
    OFN_NONETWORKBUTTON = &H20000
    OFN_NOREADONLYRETURN = &H8000
    OFN_NOTESTFILECREATE = &H10000
    OFN_NOVALIDATE = &H100
    OFN_OVERWRITEPROMPT = &H2
    OFN_PATHMUSTEXIST = &H800
    OFN_READONLY = &H1
    OFN_SHAREAWARE = &H4000
    OFN_SHAREFALLTHROUGH = 2
    OFN_SHARENOWARN = 1
    OFN_SHAREWARN = 0
    OFN_SHOWHELP = &H10
End Enum

Function ShowSaveFileDialog(ByVal sFilter As String, _
    Optional ByVal sDefExt As _
    String, Optional ByVal sInitDir As String, Optional ByVal lFlags As Long, _
    Optional ByVal hParent As Long) As String

   ' Zobrazφ dialog pro v²b∞r souboru k ulo₧enφ. Vracφ bu∩ cestu k vybranΘmu souboru nebo
   ' nulov² °et∞zec, pokud je dialog stornovßn
   ' Parametry:
   '  - sFilter: specifikuje filtr zobrazovan²ch soubor∙
   '  - sDefExt: defaultnφ p°φpona asociovanß se jmΘnem souboru pokud ₧ßdnß nenφ 
   '                  u₧ivatelem specifikovßna
   '  - sInitDir: adresß°, kde se mß dialog otev°φt
   '  - lFlag: parametry pro dialog. P°eΦt∞te si nßpov∞du pro Common Dialogs
   '  - hParent: ukazatel na rodiΦovsk² formulß°


   ' P°φklad:
   '    Dim sFilter As String
   '    sFilter = "TextovΘ soubory (*.txt)|*.txt|VÜechny soubory (*.*)|*.*"
   '    MsgBox ShowOpenFileDialog(sFilter, "txt", "C:\Documents", OFN_OVERWRITEPROMPT)

    Dim OFN As OpenFilename
    On Error Resume Next
    
    With OFN
        .lStructSize = Len(OFN)
        .hwndOwner = hParent
        .lpstrFilter = Replace(sFilter, "|", vbNullChar) & vbNullChar
        .lpstrFile = Space$(255) & vbNullChar & vbNullChar
        .nMaxFile = Len(.lpstrFile)
        .flags = lFlags
        .lpstrInitialDir = sInitDir
        .lpstrDefExt = sDefExt
    End With
    
    If GetSaveFileName(OFN) Then
        ShowSaveFileDialog = Left$(OFN.lpstrFile, InStr(OFN.lpstrFile, _
            vbNullChar) - 1)
    End If
End Function

Zp∞t

Autor: The Bozena