📄 mopenfiledlg.bas
字号:
Attribute VB_Name = "mOpenFileDlg"
'---------------------------------------------------------------------------------------
' Module : mOpenFileDlg
' DateTime : 2006-12-2 13:16
' Author : kmlxk
' Purpose : 打开文件对话框
' Requires :
' Sample :
' Dim sFileName As String
' sFileName = mOpenFileDlg.OpenFileDlg("VB工程文件(*.vbp)|*.vbp|所有文件(*.*)|*.*")
' If Len(sFileName) > 0 Then
' Text1.Text = sFileName
' End If
'---------------------------------------------------------------------------------------
Option Explicit
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
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
Public Function SaveFileDlg(Optional ByVal sFilter As String, Optional ByVal sTitle As String, Optional ByVal sDirectory As String, Optional ByVal hwnd As Long, Optional ByVal sDefaultExt As String) As String
Dim ofn As OPENFILENAME
ofn.lStructSize = Len(ofn)
ofn.lpstrDefExt = sDefaultExt
ofn.hWndOwner = hwnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = Replace(sFilter, "|", Chr(0)) & Chr(0)
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = sDirectory
ofn.lpstrTitle = sTitle
ofn.flags = 0
If GetSaveFileName(ofn) Then
SaveFileDlg = Trim$(ofn.lpstrFile)
Else
SaveFileDlg = ""
End If
End Function
Public Function OpenFileDlg(Optional ByVal sFilter As String, Optional ByVal sTitle As String, Optional ByVal sDirectory As String, Optional ByVal hwnd As Long) As String
Dim ofn As OPENFILENAME
Dim strFileName As String
ofn.lStructSize = Len(ofn)
ofn.hWndOwner = hwnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = Replace(sFilter, "|", Chr(0)) & Chr(0)
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = sDirectory
ofn.lpstrTitle = sTitle
ofn.flags = 0
Dim a As Long
a = GetOpenFileName(ofn)
If (a) Then
strFileName = Trim$(ofn.lpstrFile)
Else
strFileName = ""
End If
OpenFileDlg = strFileName
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -