实现效果:
知识运用:
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 }