首先,你需要在程序的一个模块中声明一个 UDT,一些常量,以及一个 API 函数。
Public Const SW_SHOW = 5
Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
' optional fields
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Public Declare Function ShellExecuteEx Lib "shell32.dll" _
(ByRef s As SHELLEXECUTEINFO) As Long
然后,所有要做的就是声明 UDT 的一个实例,以必要的信息载入这个实例,然后调用特定的函数。
Dim shInfo As SHELLEXECUTEINFO
With shInfo
.cbSize = LenB(shInfo)
.lpFile = FullPathAndNameOfFile
.nShow = SW_SHOW
.fMask = SEE_MASK_INVOKEIDLIST
.lpVerb = "properties"
End With
ShellExecuteExshInfo
如果你对一个不存在的文件运行该程序时,Windows 会弹出一个消息,告诉你文件不存在。但是不会有运行时期错误。