Last Updated 2005/09/09
Programming Tips Visual C++ API  索 引 
CD Driveの開閉
2005/09/09

winmm.lib をプロジェクトに追加する.

#include <mmsystem.h>

    MCI_ANIM_OPEN_PARMS open = {0, 0, 0, 0, 0, 0, 0};

    // MCI オープン
    open.dwCallback = (DWORD)this->m_hWnd;
    open.lpstrDeviceType = "cdaudio";
    open.lpstrElementName = "";
    open.hWndParent = this->m_hWnd;

    MCIERROR er = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE, (DWORD)&open);

    char buf[100];
    mciGetErrorString(er, buf, 100);

    // CD オープン
    MCI_SET_PARMS set;
    set.dwCallback = (DWORD)this->m_hWnd;
    set.dwTimeFormat = MCI_FORMAT_TMSF;
    set.dwAudio = 0;
    er = mciSendCommand(open.wDeviceID, MCI_SET,
                         MCI_SET_DOOR_OPEN,
                         //MCI_SET_DOOR_CLOSED,  閉じる場合はこっち
                         (DWORD)&set);

    // MCIをクローズ
    MCI_GENERIC_PARMS close;
    close.dwCallback = (DWORD)this->m_hWnd;

    mciSendCommand(open.wDeviceID, MCI_CLOSE,0, (DWORD)&close);


参照
前後のTips
CD Driveの開閉

DSS ProgrammingTipsCGI Ver2.01