根据cd / dvd托盘位置启用/禁用按钮 [英] Enable/disable button based on cd/dvd tray position

查看:131
本文介绍了根据cd / dvd托盘位置启用/禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序上有一个按钮,需要根据cd / dvd托盘位置启用/禁用。如果托盘已打开,则应禁用该按钮,否则启用该按钮。有人请帮帮我。

I have a button on my application which is needed to enabled/disabled based on cd/dvd tray position. If the tray is opened the button should be disable, else enabled. Somebody please help me on that.

推荐答案

没有Windows API函数来获取光驱托盘的打开/关闭状态。您可以使用 DeviceIoCtl()来检查此类驱动器是否插入了介质,表明托盘实际已关闭。



要在托盘关闭或使用插入的介质打开时收到通知,请在应用程序中添加 WM_DEVICECHANGE 处理程序,并对 DBT_DEVICEARRIVAL DBT_DEVICEREMOVECOMPLETE 。请参阅如何接收插入或移除CD-ROM的通知 [ ^ ]。



如果您确实需要在未插入介质时知道托盘的状态,则必须通过使用调用 DeviceIoCtl()直接询问驱动器IOCTL_SCSI_PASSTHROUGH 提供所需的SCSI命令描述符块(发送请求检测命令并检查返回的密钥代码限定符以查找未就绪 - 托盘打开/关闭错误)。
There is no Windows API function to get the open/close state for the tray of optical drives. You can use DeviceIoCtl() to check if such a drive has a media inserted indicating that the tray is actually closed.

To get notifications when the tray is closed or opened with inserted media, add a WM_DEVICECHANGE handler to your application and act upon DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE. See How to receive notification of CD-ROM insertion or removal[^] in the MSDN.

If you really need to know the state of the tray when no media is inserted, you must directly ask the drive by calling DeviceIoCtl() with IOCTL_SCSI_PASSTHROUGH providing the required SCSI command descriptor blocks (send a Request Sense Command and check the returned Key Code Qualifier for the Not Ready - Tray open/close errors).


这篇关于根据cd / dvd托盘位置启用/禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆