相关原理资料附上Although it was hard to find the information, the trick how to do it is basically very easy. Windows broadcasts a WM_DEVICECHANGE event to every top-level window in the system when you insert of eject the cdrom. The message is send to the WindowProc function of the windows. You can subclass your own window to intercept it (VB won't give you another option) or you can create a hook. Personnally I prefer the subclassing.Ejection:
Msg = WM_DEVICECHANGE
wParam = DBT_DEVICEREMOVECOMPLETE
lParam = pointer to DEV_BROADCAST_HDR structureInsertion:
Msg = WM_DEVICECHANGE
wParam = DBT_DEVICEARRIVAL
lParam = pointer to DEV_BROADCAST_HDR structureTo know if it's really a cdrom that causes this message you'll have to read the structure. You won't find the structure in API Viewer provided with VB, so I give you a translation of the SDK C++ style definition:Type DEV_BROADCAST_HDR
   dbch_size As Long
   dbch_devicetype As Long
   dbch_reserved As Long
End TypeIf the dbch_devidetype member is set to DBT_DEVTYP_VOLUME (Logical Volume), it most probably is a cdrom ejection/insertion. Of course, it can also be a Zip-disk, Jazz-drive dvd-drive and so on. To determine that, copy the same memory address this structure pointed to to a DBT_DEVTYP_VOLUME structure. That structure has two more members, and looks as follows:Type DBT_DEVTYP_VOLUME
   dbcv_size As Long
   dbcv_devicetype As Long
   dbcv_reserved As Long
   dbcv_unitmask As Long
   dbcv_flags As Integer
End TypeThe bits in the dbcv_unitmask member indicates the drive(s) this event applies to. Bit 0 represents drive A, bit 1 represents drive B and so on. You can use that information to determine if the drive is a cdrom drive. The dbcv_flags member can be used to test for the case it affects media in a (physical or not) drive or a network volume. From the SDK:DBTF_MEDIA     Change affects media in drive. If not set, change affects physical device or drive. 
DBTF_NET           Indicated logical volume is a network volume. 
With this information it should be a breeze to create a handler to handle the ejection or insertion of the cdrom drive.