上次我介绍了一下如何用VB实现和陌生人聊天(点击查看),现在介绍一下如何用VB编程实现弹光驱功能。我要说一句,其实我的VB水平很菜,也就是刚刚入门。如果以后有时间会继续学习的。
实现此功能的完整代码如下所示:
'添加 Command1
Option Explicit
Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long
Private Sub Form_Load()
Command1.Caption = "弹 出"
End Sub
Private Sub Command1_Click()
If Command1.Caption = "弹 出" Then
mciExecute "set cdaudio door open" '弹出光驱
Command1.Caption = "关 闭"
Else
mciExecute "set cdaudio door closed" '关闭光驱
Command1.Caption = "弹 出"
End If
End Sub
你只需要把代码复制到新窗体中就可以了。

