什么是代码openclose C#中的CD托盘 [英] whats the code openclose cd tray in C#

查看:123
本文介绍了什么是代码openclose C#中的CD托盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请发送我的电子邮件代码-bbsr.basanta@gmail.com

Please send code my email -bbsr.basanta@gmail.com

推荐答案

您需要使用Win32 API:

You need to use Win32 API:

//Namespace references
using System.Text;
using System.Runtime.InteropServices;

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

//Method
#region Open/Close CD Tray
/// <summary>
/// method to open or close the CD tray based on the
/// boolean value passed
/// </summary>
/// <param name="open"></param>
/// <returns></returns>
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;
    }
}
#endregion


(我没有写这个,但是我忘了从哪里得到的...)

顺便说一句:除非您真的喜欢垃圾邮件,否则请不要在论坛中发布您的电子邮件!


(I didn''t write this, but I forget where I got it from...)

BTW: Don''t post your email in forums unless you really like spam!


这篇关于什么是代码openclose C#中的CD托盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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