使用Windows系统编程可以实现,呵呵这个是很容易的下次写个程序。你只要在任意驱动器上点击右键,里面会有一项“关闭光驱”呵呵,点击后,光驱即可关闭。
解决方案 »
- 关于类的Class_Initialize
- 关于函数的调用
- 急:ListView的多行选择问题???
- 关于RealAudio1?
- Public gintSmode As Integer 为什么提示用户定义类型未定义
- 如何在vb中到如flash动画
- Runtime error的错误
- 怎样用ActiveReport在同一页面上打印多个记录集?
- ShockwaveFlash1.SetVariable "commentMC.input_txt.text", "aaaaaa"
- VB 中怎样响应系统消息 如 WM_PAINT 之类的?
- 在1至100中产生20个不重复的随机数
- 懂程序的进来,我在做毕业设计!请各位高手指点(VB)
Private Const MCI_OPEN_TYPE = &H2000&
Private Const MCI_OPEN_SHAREABLE = &H100&
Private Const MCI_SET = &H80D
Private Const MCI_SET_DOOR_OPEN = &H100&
Private Const MCI_CLOSE = &H804
Private Type MCI_OPEN_PARMS
dwCallback As Long
wDeviceID As Long
lpstrDeviceType As String
lpstrElementName As String
lpstrAlias As String
End Type
Private Declare Function mciSendCommand Lib "winmm.dll" Alias "mciSendCommandA" (ByVal wDeviceID As Long, ByVal uMessage As Long, ByVal dwParam1 As Long, ByRef dwParam2 As Any) As Long
Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Dim openParams As MCI_OPEN_PARMS
Private Sub Form_Load()
'KPD-Team 2001
'URL: http://www.allapi.net/
'[email protected]
Dim lRet As Long
'initialize the structure
openParams.wDeviceID = 0
openParams.lpstrDeviceType = "cdaudio"
'get the device ID
lRet = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, openParams)
'check for error
If lRet <> 0 Then
'show error
MsgBox GetMCIErrorString(lRet), vbCritical
Else
'open the door of the CD-ROM drive
lRet = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal 0&)
'check for errors
If lRet <> 0 Then MsgBox GetMCIErrorString(lRet), vbCritical
End If
'clean up
mciSendCommand openParams.wDeviceID, MCI_CLOSE, 0, ByVal 0&
End Sub
Private Function GetMCIErrorString(lErr As Long) As String
'create a buffer
GetMCIErrorString = Space$(255)
'retrieve the error string
mciGetErrorString lErr, GetMCIErrorString, Len(GetMCIErrorString)
'strip off the trailing spaces
GetMCIErrorString = Trim$(GetMCIErrorString)
End Function
Private Const MCI_OPEN_TYPE = &H2000&
Private Const MCI_OPEN_SHAREABLE = &H100&
Private Const MCI_SET = &H80D
Private Const MCI_SET_DOOR_OPEN = &H100&
Private Const MCI_CLOSE = &H804'×Ô¶¨ÒåÀàÐÍ MCI_OPEN_PARMS
Private Type MCI_OPEN_PARMS
dwCallback As Long
wDeviceID As Long
lpstrDeviceType As String
lpstrElementName As String
lpstrAlias As String
End Type
Private Declare Function mciSendCommand Lib "winmm.dll" _
Alias "mciSendCommandA" (ByVal wDeviceID As Long, _
ByVal uMessage As Long, _
ByVal dwParam1 As Long, _
ByRef dwParam2 As Any) As Long
Private Declare Function mciGetErrorString Lib "winmm.dll" _
Alias "mciGetErrorStringA" (ByVal dwError As Long, _
ByVal lpstrBuffer As String, _
ByVal uLength As Long) As Long'Private Declare Function GetmciErrorString Lib "winmm.dll" _
' Alias "GetmciErrorStringA" (ByVal llRet As Long) As Long
Dim openParams As MCI_OPEN_PARMSPrivate Sub Command1_Click()
'KPD-Team 2001
'URL: http://www.allapi.net/
'[email protected]
Dim lRet As Long
'initialize the structure
openParams.wDeviceID = 0
openParams.lpstrDeviceType = "cdaudio"
'get the device ID
lRet = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, openParams)
'check for error
If lRet <> 0 Then
'show error
MsgBox GetmciErrorString(lRet), vbCritical
Else
'open the door of the CD-ROM drive
lRet = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal 0&)
'check for errors
If lRet <> 0 Then MsgBox GetmciErrorString(lRet), vbCritical
End If
'clean up
mciSendCommand openParams.wDeviceID, MCI_CLOSE, 0, ByVal 0&
End Sub
出现一个自定义的选项,比如关闭光驱。
出现一个自定义的选项,比如关闭光驱。是不是要通过修改注册表
出现一个自定义的选项,比如关闭光驱。是不是要通过修改注册表
但是,你也可以通过修改注册表来实现类似的效果,不过这样会使在任何驱动器的右键菜单中都出现这个项,方法如下:
在驱动器及系统文件图标上的弹出菜单: 运行regedit.exe,打开HKEY_CLASSES_ROOT\Folder\shell 如要删除一条,选择其下的一条主键,按Del删除。如要增加,在shell子键上按右键,选择新建主键,在其默认项内设置其标题, 然后在你新建的主键下再新建一条名为command的主键,在其默认项内设置你要运行的程序的完整路径。
既然全部要在VB代码中实现,因此应当使用写注册表的API来进行此修改,同时,编译这个VB程序为可执行文件,一运行就mcisendstring "set cdaudio door closed",0&,0&,0&.即可。
mcisendstring "set CDAudio door close"