打开或关闭CD_ROM

Posted on 2019-01-16 17:28  努力成长静待花开  阅读(355)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  API函数 mciSendString  //函数用来向媒体控制接口设备发送命令  声明如下

[DllImport("winmm.dll",EntryPoint="mciSendString")]
public static extern int mciSendString(string IpstrCommand,string IpstrReturnString,System.UInt16 uReturnLength,System.IntPtr HwndCallback);

 实现代码:

    [DllImport("winmm.dll",EntryPoint="mciSendString")]
    public static extern int mciSendString(string IpstrCommand,string IpstrReturnString,System.UInt16 uReturnLength,System.IntPtr HwndCallback);

    private void button1_Click(object sender, EventArgs e)
    {
        mciSendString("Set cdaudio door open wait","",0,this.Handle);         //打开CD_ROM
    }

    private void button2_Click(object sender, EventArgs e)
    {
        mciSendString("Set cdaudio door closed wait", "", 0, this.Handle);     //关闭CD_ROM
    }