Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function ShellExecuteForExplore Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, lpParameters As Any, lpDirectory As Any, ByVal nShowCmd As Long) As Long
'窗口显示方式枚举
Public Enum EShellShowConstants
essSW_HIDE = 0
essSW_MAXIMIZE = 3
essSW_MINIMIZE = 6
essSW_SHOWMAXIMIZED = 3
essSW_SHOWMINIMIZED = 2
essSW_SHOWNORMAL = 1
essSW_SHOWNOACTIVATE = 4
essSW_SHOWNA = 8
essSW_SHOWMINNOACTIVE = 7
essSW_SHOWDEFAULT = 10
essSW_RESTORE = 9
essSW_SHOW = 5
End EnumPublic Function ShellEx( _
ByVal sFile As String, _
Optional ByVal eShowCmd As EShellShowConstants = essSW_SHOWDEFAULT, _
Optional ByVal sParameters As String = "", _
Optional ByVal sDefaultDir As String = "", _
Optional sOperation As String = "open", _
Optional Owner As Long = 0 _
) As Boolean
Dim lR As Long
Dim lErr As Long, sErr As Long
If (InStr(UCase$(sFile), ".EXE") <> 0) Then
eShowCmd = 0
End If
On Error Resume Next
If (sParameters = "") And (sDefaultDir = "") Then
lR = ShellExecuteForExplore(Owner, sOperation, sFile, 0, 0, essSW_SHOWNORMAL)
Else
lR = ShellExecute(Owner, sOperation, sFile, sParameters, sDefaultDir, eShowCmd)
End If
If (lR < 0) Or (lR > 32) Then
ShellEx = True
Else
ShellEx = False
End If
End Function
以下为例子
设置记录文件路径的字段的按钮属性有效
With grdDataGrid
.Columns(3).Button = True
End WithPrivate Sub grdDataGrid_ButtonClick(ByVal ColIndex As Integer)
Select Case ColIndex
Case 3
'当按下按钮时打开文件
Call ShellEx(grdDataGrid.Text)
End Select
End Sub
Private Declare Function ShellExecuteForExplore Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, lpParameters As Any, lpDirectory As Any, ByVal nShowCmd As Long) As Long
'窗口显示方式枚举
Public Enum EShellShowConstants
essSW_HIDE = 0
essSW_MAXIMIZE = 3
essSW_MINIMIZE = 6
essSW_SHOWMAXIMIZED = 3
essSW_SHOWMINIMIZED = 2
essSW_SHOWNORMAL = 1
essSW_SHOWNOACTIVATE = 4
essSW_SHOWNA = 8
essSW_SHOWMINNOACTIVE = 7
essSW_SHOWDEFAULT = 10
essSW_RESTORE = 9
essSW_SHOW = 5
End EnumPublic Function ShellEx( _
ByVal sFile As String, _
Optional ByVal eShowCmd As EShellShowConstants = essSW_SHOWDEFAULT, _
Optional ByVal sParameters As String = "", _
Optional ByVal sDefaultDir As String = "", _
Optional sOperation As String = "open", _
Optional Owner As Long = 0 _
) As Boolean
Dim lR As Long
Dim lErr As Long, sErr As Long
If (InStr(UCase$(sFile), ".EXE") <> 0) Then
eShowCmd = 0
End If
On Error Resume Next
If (sParameters = "") And (sDefaultDir = "") Then
lR = ShellExecuteForExplore(Owner, sOperation, sFile, 0, 0, essSW_SHOWNORMAL)
Else
lR = ShellExecute(Owner, sOperation, sFile, sParameters, sDefaultDir, eShowCmd)
End If
If (lR < 0) Or (lR > 32) Then
ShellEx = True
Else
ShellEx = False
End If
End Function
以下为例子
设置记录文件路径的字段的按钮属性有效
With grdDataGrid
.Columns(3).Button = True
End WithPrivate Sub grdDataGrid_ButtonClick(ByVal ColIndex As Integer)
Select Case ColIndex
Case 3
'当按下按钮时打开文件
Call ShellEx(grdDataGrid.Text)
End Select
End Sub
解决方案 »
- 关于图片分割和亮度识别的问题~!!!
- VB6.0中编写ActiveX,如何应用类摸板
- 如何在Listview中加载PictureBox????
- 做打包程序的一个问题?
- 一个关于TCP协议的问题,急!
- 如何在form中放置coreldraw生成的wmf 纯矢量图形
- 有关图片打印的问题,请大家帮忙?在线等待
- 同一串口,多个mscomm问题
- VB 错误的文件名或号码
- activex中如何读取外部传入的参数值?即<object><param name="height" value="4"></object>中height的值如何在vb中获得?谢谢!!!
- 关于VB6的工具栏
- loveyxy 你还没有收到我的Email 吗?
Const SW_SHOWNORMAL = 1
Private Sub Form_Load()
ShellExecute Me.hwnd, vbNullString, "mailto:[email protected]", vbNullString, "C:\", SW_SHOW
ShellExecute Me.hwnd, vbNullString, "d:\1.txt", vbNullString, "C:\", SW_SHOWNORMAL
ShellExecute Me.hwnd, vbNullString, "d:\sample.jpg", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
Dim x As New IWshRuntimeLibrary.IWshShell_Class
x.Run "d:\恶意.txt"
x.Run "d:\恶意.xls"