如何打开和关闭CD/DVD驱动器托盘? [英] How to Open and Close CD/DVD Drive Tray ?

查看:199
本文介绍了如何打开和关闭CD/DVD驱动器托盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周,找不到想要解决的简单解决方案.

我想从我的C#应用​​程序中打开CD-ROM.它应该检查介质是否实际上是CD-ROM,然后将其打开.

I have looked around and can''t find a simple solution to what I want to do.

I want to open a CD-Rom from my C# app. It should check if the media is in fact a cd- rom and then open it. Is there a quick solution to this or am I missing something?

推荐答案

尝试以下方法:

打开和关闭CD/DVD驱动器托盘 [ ^ ]
Try this:

Open and Close CD/DVD Drive Tray[^]


尝试以下方法:

http://en.csharp-online.net/Open/close_CD_drive_tray

http://www.vcskicks.com/disk-drive.php

http://www.dreamincode.net/code/snippet1692.htm
Try these:

http://en.csharp-online.net/Open/close_CD_drive_tray

http://www.vcskicks.com/disk-drive.php

http://www.dreamincode.net/code/snippet1692.htm


使用
Using the code from Open & close CD tray in C#
Create the following class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//Namespace references
using System.Runtime.InteropServices;

namespace dummyProj1
{
    class DVD
    {
        //Win32 API Call
        [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)]
        protected static extern int mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, IntPtr hwndCallback);

        public bool ProcessCDTray(bool open)
        {
            int ret = 0;
            //do a switch of the value passed
            switch (open)
            {
                case true:  //true = open the cd
                    ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero);
                    return true;
                    //break;
                case false: //false = close the tray
                    ret = mciSendString("set cdaudio door closed", null, 0, IntPtr.Zero);
                    return true;
                    //break;
                default:
                    ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero);
                    return true;
                    //break;
            }
        }
    }
}



要打开DVD托盘,请使用以下代码:



To Open the DVD Tray, use the following bit of code:

DVD thedvd = new DVD();
//Open CD Tray
thedvd.ProcessCDTray(true);

//To Close the CD Tray
thedvd.ProcessCDTray(false);


这篇关于如何打开和关闭CD/DVD驱动器托盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆