- Home
·
- Registry
·
- Copy the contents to a Class module and you've got a standard common dialog class, without using th
Copy the contents to a Class module and you've got a standard common dialog class, without using th
Copy the contents to a Class module and you've got a standard common dialog class, without using the common dialog control
API Declarations
'API function declaration
Private 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
'DLL function declaration
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenFileName As OPENFILENAME) As Long
'Module level variable declaration
Private mstrFileName As String
Private mstrInitDir As String
Private mstrDialogTitle As String
Private mstrFilter As String
Rate Copy the contents to a Class module and you've got a standard common dialog class, without using th
(2(2 Vote))
FileName = mstrFileName
End Property
Public Property Let FileName(ByVal NewValue As String)
mstrFileName = NewValue
End Property
Public Property Get InitDir() As String
InitDir = mstrInitDir
End Property
Public Property Let InitDir(ByVal NewValue As String)
mstrInitDir = NewValue
End Property
Public Property Get DialogTitle() As String
DialogTitle = mstrDialogTitle
End Property
Public Property Let DialogTitle(ByVal NewValue As String)
mstrDialogTitle = NewValue
End Property
Public Property Get Filter() As String
Filter = mstrFilter
End Property
Public Property Let Filter(ByVal NewValue As String)
mstrFilter = NewValue
End Property
Private Sub Class_Initialize()
mstrFileName = ""
mstrInitDir = App.Path
mstrDialogTitle = App.Title
mstrFilter = "All Files (*.*) " & Chr(0) & "*.*" & Chr(0)
End Sub
Public Function OpenDialog(Optional NewFileName As String, Optional NewFilter As String, Optional NewTitle As String) As String
Dim OpenFile As OPENFILENAME
Dim lngReturn As Long
Dim strFilter As String
Dim strFileName As String
Dim strDialogTitle As String
Dim intSize As Integer
If IsMissing(NewFilter) Or NewFilter = "" Then
strFilter = mstrFilter
Else
strFilter = NewFilter
End If
If IsMissing(NewFileName) Or NewFileName = "" Then
strFileName = mstrFileName
Else
strFileName = NewFileName
End If
If IsMissing(NewTitle) Or NewTitle = "" Then
strDialogTitle = mstrDialogTitle
Else
strDialogTitle = NewTitle
End If
intSize = 257 - Len(strFileName)
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hInstance = App.hInstance
OpenFile.lpstrFilter = strFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = strFileName & String(intSize, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = mstrInitDir
OpenFile.lpstrTitle = strDialogTitle
OpenFile.flags = 0
lngReturn = GetOpenFileName(OpenFile)
If lngReturn = 0 Then
OpenDialog = ""
Else
OpenDialog = OpenFile.lpstrFile
End If
End Function
Copy the contents to a Class module and you've got a standard common dialog class, without using th Comments
No comments yet — be the first to post one!
Post a Comment