The Function of check if the CD-ROM's door opened or closed?
-
Can anyone send me the code of check CD-ROM's door opened or closed? Such as: BOOL CXXXXX::CheckCDDoorOpenedOrClosed() { .... } Thanks.:) A VC++ beginer
-
Can anyone send me the code of check CD-ROM's door opened or closed? Such as: BOOL CXXXXX::CheckCDDoorOpenedOrClosed() { .... } Thanks.:) A VC++ beginer
Have a look into MSDN document HOWTO: Getting Notification of CD-ROM Insertion or Removal Here is the sample code from it Sample Code The following code demonstrates how to use the WM_DEVICECHANGE message to check for compact disc or DVD insertion or removal. #include #include char FirstDriveFromMask (ULONG unitmask); //prototype /*---------------------------------------------------------------------- Main_OnDeviceChange (hwnd, wParam, lParam) Description Handles WM_DEVICECHANGE messages sent to the application's top-level window. ----------------------------------------------------------------------*/ void Main_OnDeviceChange (HWND hwnd, WPARAM wParam, LPARAM lParam) { PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam; char szMsg[80]; switch(wParam) { case DBT_DEVICEARRIVAL: // See if a CD-ROM or DVD was inserted into a drive. if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME) { PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb; if (lpdbv -> dbcv_flags & DBTF_MEDIA) { wsprintf (szMsg, "Drive %c: arrived\n", FirstDriveFromMask(lpdbv ->dbcv_unitmask)); MessageBox (hwnd, szMsg, "WM_DEVICECHANGE", MB_OK); } } break; case DBT_DEVICEREMOVECOMPLETE: // See if a CD-ROM was removed from a drive. if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME) { PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb; if (lpdbv -> dbcv_flags & DBTF_MEDIA) { wsprintf (szMsg, "Drive %c: was removed\n", FirstDriveFromMask(lpdbv ->dbcv_unitmask)); MessageBox (hwnd, szMsg, "WM_DEVICECHANGE", MB_OK); } } break; default: /* Other WM_DEVICECHANGE notifications get sent for other devices or reasons; we don't care about them here. If they were important, we would check for them and act accordingly. */ ; } } /*---------------------------------------------------------------------- FirstDriveFromMask (unitmask) Finds the first valid drive letter from a mask of drive letters. The mask must be in the format bit 0 = A, bit 1 = B, bit 3 = C, etc. A valid drive letter is