Public Declare Function GetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
'Now come some Types.
Public Enum GFNFlags
OFN_ALLOWMULTISELECT = &H200
OFN_CREATEPROMPT = &H2000
OFN_EXPLORER = &H80000
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
End Enum
Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex 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
'This is the wrapper Function.
Public Function SaveDialog(ByVal OwnerhWnd As Long, _
ByVal Filters As String, ByVal FilterIndex As Long, _
ByVal FNameLength As Long, _
Optional ByVal InitFolder As String = "", _
Optional ByVal InitFileName As String = "", _
Optional ByVal dlgTitle As String = "", _
Optional ByVal Flags As GFNFlags = 0) As String
'Dimension some variables.
Dim GFN As OPENFILENAME
'Sort out some of the Type we will pass.
GFN.lStructSize = Len(GFN)
GFN.hwndOwner = OwnerhWnd
GFN.hInstance = App.hInstance
'Sort out the filters.
For I = 1 To Len(Filters)
If Mid$(Filters, I, 1) = "|" Then
Filters = Left$(Filters, I - 1) & Chr$(0) & _
Right$(Filters, Len(Filters) - I)
End If
Next
'Finish setting up the Type.
GFN.lpstrFilter = Filters
GFN.nFilterIndex = FilterIndex
GFN.lpstrFile = InitFileName & String$(FNameLength - Len(InitFileName), Chr$(0))
GFN.nMaxFile = FNameLength
GFN.lpstrFileTitle = String$(FNameLength, Chr$(0))
GFN.nMaxFileTitle = FNameLength
GFN.lpstrInitialDir = InitFolder
GFN.lpstrTitle = dlgTitle
GFN.Flags = Flags
'Get and return the filename.
If GetSaveFileName(GFN) >= 1 Then
SaveDialog = GFN.lpstrFile
Else
SaveDialog = Chr$(0)
End If
End Function
No comments:
Post a Comment