|
-
Jul 13th, 2000, 12:05 AM
#1
Thread Starter
Fanatic Member
I was told that someone posted a way to avoid adding a CommonDialog control to your form but still being able to use it's functions...can anyone recall something like that being posted, cause ic an't seem to find it.
-
Jul 13th, 2000, 01:13 AM
#2
Lively Member
For the FileOpen / FileSave function, you can use this piece of code
Code:
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (ofn As OPENFILENAME) As Boolean
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (ofn As OPENFILENAME) As Boolean
'
Private Type OPENFILENAME
lStructSize As Long
hWndOwner As Long
hInstance As Long
StrFilter As String
strCustomFilter As String
nMaxCustFilter As Long
NFilterIndex As Long
strFile As String
nMaxFile As Long
strFileTitle As String
nMaxFileTitle As Long
strInitialDir As String
strTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
strDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
'
Public Const OFN_READONLY = &H1
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_SHOWHELP = &H10
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &H10000
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOLONGNAMES = &H40000
Public Const OFN_EXPLORER = &H80000
Public Const OFN_NODEREFERENCELINKS = &H100000
Public Const OFN_LONGNAMES = &H200000
'
Public Function FileSaveOpen( _
Optional ByVal OpenDialog, _
Optional ByRef Flags, _
Optional ByVal InitDir, _
Optional ByVal FileName, _
Optional ByVal BoxTitle, _
Optional ByVal Filters, _
Optional ByVal DefaultFilter, _
Optional ByVal DefaultExt _
) As String
' Parameters:
' OpenDialog: False = Open, True = Save
' Flags: Standard api flag constants. (modified by reference)
' InitDir: Initial dir to show
' FileName: Default file name
' BoxTitle: Dialog's Caption
' Filters: Standard file filters ('|' delimited string)
' DefaultFilter: Default Filter to use
' DefaultExt: Default extension to use for save dialog
'
'Return Value:
' Selected file's full path. "" if Cancelled
Dim Dlg As OPENFILENAME
Dim ret As Boolean
Dim n As Integer
'
On Error GoTo FileSaveOpen_Err
'
Const BufferLen As Integer = 512
'
If IsMissing(OpenDialog) Then OpenDialog = False
If IsMissing(Flags) Then Flags = OFN_HIDEREADONLY
If IsMissing(InitDir) Then InitDir = CurDir
If IsMissing(FileName) Then FileName = ""
If IsMissing(BoxTitle) Then BoxTitle = ""
If IsMissing(Filters) Then Filters = "All Files (*.*)|*.*|"
If IsMissing(DefaultFilter) Then DefaultFilter = 1
If IsMissing(DefaultExt) Then DefaultExt = ""
FileName = Left$(FileName & String$(BufferLen, vbNullChar), BufferLen)
'
For n = 1 To Len(Filters)
If Mid$(Filters, n, 1) = "|" Then Mid$(Filters, n) = vbNullChar
Next
'
With Dlg
.lStructSize = Len(Dlg)
.hWndOwner = Application.hWndAccessApp
.StrFilter = Filters
.NFilterIndex = DefaultFilter
.strFile = FileName
.nMaxFile = BufferLen
.strTitle = BoxTitle
.Flags = Flags
.strDefExt = DefaultExt
.strInitialDir = InitDir
.nMaxCustFilter = BufferLen
.strCustomFilter = String$(BufferLen, vbNullChar)
End With
If OpenDialog Then
ret = GetSaveFileName(Dlg)
Else
ret = GetOpenFileName(Dlg)
End If
If ret Then
FileSaveOpen = Left(Dlg.strFile, InStr(Dlg.strFile, vbNullChar) - 1)
Flags = Dlg.Flags
End If
FileSaveOpen_Fin:
Exit Function
FileSaveOpen_Err:
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|