15,471
社区成员
发帖
与我相关
我的任务
分享
Private Declare Function GetOpenFileName Lib "comdlg32.dll " Alias "GetOpenFileNameA " (pOpenfilename As OPENFILENAME) As Long
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
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
Public Function OpenFileDlg(hwnd As Long,Title as string) As String
Dim OFDlg As OPENFILENAME
With OFDlg
.lStructSize = Len(ofd)
.hwndOwner = hwnd
.hInstance = App.hInstance
.lpstrFilter = "*.* " + Chr$(0) + "*.* " + Chr$(0)
.lpstrFile = Space$(254)
.lpstrFileTitle = Space$(254)
.nMaxFile = 255
.nMaxFileTitle = 255
.lpstrInitialDir = CurDir
.lpstrTitle = title
.flags = 0
End With
If GetOpenFileName(ofd) Then OpenFileDlg = Left(OFDlg.lpstrFile, InStr(OFDlg.lpstrFile, Chr(0)) - 1)
End Function
Public Function SaveFileDlg(hwnd As long,Title as string) As String
Dim SFDlg As OPENFILENAME
With SFDlg
.lStructSize = Len(SFDlg)
.hwndOwner = hwnd
.hInstance = App.hInstance
.lpstrFile = Space(254)
.lpstrFileTitle = Space(254)
.nMaxFile = 255
.nMaxFileTitle = 255
.lpstrInitialDir = App.Path
.flags = 6148 Or &H2
.lpstrFilter = "*.* " + Chr$(0) + "*.* "
.lpstrTitle = title
If GetSaveFileName(SFDlg) > = 1 Then
SaveFileDlg = Left(.lpstrFile, InStr(.lpstrFile, Chr(0)) - 1)
End If
End With
End Function