颤音记号与震音记号:请教一下在VB中怎样运行外部程序

来源:百度文库 编辑:高考问答 时间:2024/04/27 13:49:47
小弟想做一个程序就是 点一下按扭1 运行 光盘上的1.exe 如果点 按扭2 就运行光盘上的 2.exe
请问 click 事件里面写什么呀 谢谢了非常想知道
另外怎样能知道光驱的盘符呀?比如说:光盘是e盘
点按扭1就运行e盘的1.exe要是光盘是f盘点按扭1就运行f盘的1.exe
谢谢了!

最直接和简单的方法就是使用Shell 函数
本示例使用 Shell 函数来完成一个用户指定的应用程序。

' 将第二个参数值设成 1,可让该程序以正常大小的窗口完成,并且拥有焦点。
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1) ' 完成Calculator。

关于光盘:用下面的的函数将检查你计算机所有的驱动器是否是 CD-ROM,如果是就返回驱动器号,如果没有就返回空字符:
Public Function BI_GetCDROMDrive() As String
Dim lType As Long
Dim i As Integer
Dim tmpDrive As String
Dim found As Boolean
On Error GoTo ErrorHandler
'Loop thru A-Z. If found, exit early.
For i = 0 To 25
tmpDrive = Chr(65 + i) & ":"
lType = GetDriveType(tmpDrive) 'Win32 API 函数
If (lType = DRIVE_CDROM) Then 'Win32 API 常数
found = True
Exit For
End If
Next
If Not found Then
tmpDrive = ""
End If
BI_GetCDROMDrive = tmpDrive
ErrorHandler:
Err.Description = "BI_GetCDROMDrive 失败:不可预料的错误。"
BI_Errorhandler
End Function

调用API函数 ShellExecute

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

shell