There is no Windows API function to get the open/close state for the tray of optical drives. You can use
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
handler to your application and act upon
. 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
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).