CD驱动器的打开与关闭

    技术2022-05-12  1

    打开、关闭某一个驱动器:  MCI_OPEN_PARMS op;  MCI_STATUS_PARMS st;  DWORD flags;  TCHAR szDriverName[] = "F:";    //驱动器名字  ::ZeroMemory (&op, sizeof(MCI_OPEN_PARMS));  op.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_CD_AUDIO;  op.lpstrElementName = szDriverName;  flags = MCI_OPEN_TYPE       | MCI_OPEN_TYPE_ID    | MCI_OPEN_ELEMENT    | MCI_OPEN_SHAREABLE;  if(!mciSendCommand (0, MCI_OPEN, flags, (unsigned long)&op))    //打开设备  {   st.dwItem = MCI_STATUS_READY;   mciSendCommand (op.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);      //打开光驱门     mciSendCommand (op.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);      //关闭光驱门  }  mciSendCommand (op.wDeviceID, MCI_CLOSE, MCI_WAIT, 0);     //关闭设备     打开、关闭所有驱动器:     int nPos;       UINT nCount = 0;       TCHAR szDrive[] = "?://";       DWORD dwDriveList = ::GetLogicalDrives ();       while(dwDriveList)       {             if(dwDriveList & 1)             {                   szDrive[0] = 0x41 + nPos;    //0x41 = 'A'                   if(::GetDriveType (szDrive) == DRIVE_CDROM)                   {                      ...    //打开或关闭名为szDrive的驱动器                   }              }             dwDriveList >>= 1;             nPos++;       }   备注:       需要引入mmsystem.h   和 winmm.lib  

    最新回复(0)