www.pudn.com > AVPhone.zip > Module2.bas
Attribute VB_Name = "Module2"
Option Explicit
'for common dialog functions
Public 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 Long
End Type
Public Declare Function GetOpenFileName Lib "COMDLG32" _
Alias "GetOpenFileNameA" (file As OPENFILENAME) As Long
Public Declare Function GetSaveFileName Lib "COMDLG32" _
Alias "GetSaveFileNameA" (file As OPENFILENAME) As Long
Public Enum EOpenFile
OFN_OVERWRITEPROMPT = &H2
OFN_HIDEREADONLY = &H4
OFN_PATHMUSTEXIST = &H800
OFN_FILEMUSTEXIST = &H1000
End Enum
'get a open file path
Public Function GetOpenFile(ByVal hwnd As Long, ByVal Index As Long) As String
Dim of As OPENFILENAME
With of
.lStructSize = Len(of)
.Flags = OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY
.hwndOwner = hwnd
.lpstrDefExt = "avi"
.lpstrFilter = "AVI Files (*.avi)" & vbNullChar & "*.avi" & vbNullChar & "Bitmap Files (*.bmp)" & vbNullChar & "*.bmp" & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & vbNullChar
.nFilterIndex = Index
Dim s As String
s = String$(256, 0)
.lpstrFile = s
.nMaxFile = 256
If GetOpenFileName(of) Then
Dim l As Long
l = InStr(.lpstrFile, vbNullChar)
If l > 0 Then
GetOpenFile = Left$(.lpstrFile, l - 1)
Else
GetOpenFile = .lpstrFile
End If
Else
Err.Raise 32755
End If
End With
End Function
'get a save file path
Public Function GetSaveASFile(ByVal hwnd As Long, ByVal Index As Long) As String
Dim of As OPENFILENAME
With of
.lStructSize = Len(of)
.Flags = (OFN_OVERWRITEPROMPT Or OFN_HIDEREADONLY)
.hwndOwner = hwnd
.lpstrDefExt = "avi"
.lpstrFilter = "AVI Files (*.avi)" & vbNullChar & "*.avi" & vbNullChar & "Bitmap Files (*.bmp)" & vbNullChar & "*.bmp" & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & vbNullChar
.nFilterIndex = Index
Dim s As String
s = String$(256, 0)
.lpstrFile = s
.nMaxFile = 256
If GetSaveFileName(of) Then
Dim l As Long
l = InStr(.lpstrFile, vbNullChar)
If l > 0 Then
GetSaveASFile = Left$(.lpstrFile, l - 1)
Else
GetSaveASFile = .lpstrFile
End If
Else
Err.Raise 32755
End If
End With
End Function