📄 mcomdlg.bas
字号:
Attribute VB_Name = "mComDlg"
Option Explicit
'***********************************************************************
'The FileOpen function was written by Domenico Statuto (dstatuto@mbox.vol.it)
'
'Visit the CCRP web site at http://www.zeode-sd.com/ccrp to download
'his freeware FileDialogs Control that encapsulates this and much more
'functionality not found in COMDLG32.OCX
'
'***********************************************************************
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 Const MAX_PATH = 255
Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_ENABLEHOOK = &H20
Public Const OFN_ENABLETEMPLATE = &H40
Public Const OFN_ENABLETEMPLATEHANDLE = &H80
Public Const OFN_EXPLORER = &H80000 '// new look commdlg
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_LONGNAMES = &H200000 '// force long names for 3.x modules
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_NODEREFERENCELINKS = &H100000
Public Const OFN_NOLONGNAMES = &H40000 '// force no long names for 4.x modules
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &H10000
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_READONLY = &H1
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_SHAREFALLTHROUGH = 2
Public Const OFN_SHARENOWARN = 1
Public Const OFN_SHAREWARN = 0
Public Const OFN_SHOWHELP = &H10
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Private Type COLORSTRUC
lStructSize As Long
hwnd As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
Flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Const CC_SOLIDCOLOR = &H80
Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As COLORSTRUC) As Long
Public Function OpenFile(ParenthWnd As Long) As String
On Error GoTo OpenFile_Error
Dim OFN As OPENFILENAME
Dim lResult As Long
'initialize sensible fields of OPENFILENAME
With OFN
.lStructSize = Len(OFN)
.Flags = OFN_EXPLORER Or OFN_HIDEREADONLY
.lpstrTitle = "Select Image"
.lpstrFilter = "Database File" & vbNullChar & "*.mdb" & vbNullChar & vbNullChar
'"Image Files" & vbNullChar & "*.bmp;*.dib;*.gif;*.jpg;*.ico;*.wmf;*.emf" & vbNullChar & _
"All Files" & vbNullChar & "*.*" & vbNullChar & vbNullChar
.lpstrFile = String$(MAX_PATH, 0)
.nMaxFile = MAX_PATH
.hwndOwner = ParenthWnd
End With
'// Show the Openfile dialog
If GetOpenFileName(OFN) Then
'remove the trailing null
OpenFile = Left$(OFN.lpstrFile, InStr(OFN.lpstrFile, Chr$(0)))
Exit Function
End If
OpenFile_Error:
Dim t As Long
'// Errors?
t = CommDlgExtendedError()
If t Then
MsgBox str(t), , "Error in OpenFileName"
End If
End Function
Public Function ShowColor(ParenthWnd As Long, Default As Long) As Long
On Error GoTo ShowColor_Error
Dim CS As COLORSTRUC, CustColor(16) As Long
CS.lStructSize = Len(CS)
CS.Flags = CC_SOLIDCOLOR
CS.lpCustColors = String$(16 * 4, 0)
CS.hwnd = ParenthWnd
'Show the dialog
If ChooseColor(CS) Then
ShowColor = CS.rgbResult
Exit Function
End If
ShowColor_Error:
Dim t As Long
t = CommDlgExtendedError()
If t Then MsgBox str(t), , "Error in ShowColor"
ShowColor = Default 'Return default colour
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -