Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. The Function of check if the CD-ROM's door opened or closed?

The Function of check if the CD-ROM's door opened or closed?

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Love In Snowing
    wrote on last edited by
    #1

    Can anyone send me the code of check CD-ROM's door opened or closed? Such as: BOOL CXXXXX::CheckCDDoorOpenedOrClosed() { .... } Thanks.:) A VC++ beginer

    W 1 Reply Last reply
    0
    • L Love In Snowing

      Can anyone send me the code of check CD-ROM's door opened or closed? Such as: BOOL CXXXXX::CheckCDDoorOpenedOrClosed() { .... } Thanks.:) A VC++ beginer

      W Offline
      W Offline
      Wolfram Steinke
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups