当检测光盘驱动器被关闭 [英] Detect when CD drive was closed
本文介绍了当检测光盘驱动器被关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我做我自己一个小项目。我需要检测,如果CD驱动器被关闭,如果它是运行的功能。
So I am making a little project for myself. I need to detect if the CD Drive was closed, and if it was, run a function.
这可能吗?
推荐答案
首先,你需要定义将打开光盘托盘中的功能:
First you will need to define the function that will be opening the disk tray:
[DllImport("winmm.dll", EntryPoint = "mciSendString")]
public static extern int mciSendStringA(string lpstrCommand, string lpstrReturnString,
int uReturnLength, int hwndCallback);
要关闭(或检查驱动器关闭时),你需要发送两个命令字符串磁盘驱动器
To close(or check if the drive is closed) the disk drive you need to send two command strings .
mciSendStringA("open " + driveLetter + ": type CDaudio alias drive" + driveLetter,
returnString, 0, 0);
mciSendStringA("set drive" + driveLetter + " door closed", returnString, 0, 0);
该函数返回 0
如果命令是。成功地执行,否则code.So你可以有一个逻辑来检查它返回一个错误
The function returns0
if the command is successfully executed or else it returns an error code.So you can have a logic to check that.
You can check the documentation of the function and also a useful link for more info
这篇关于当检测光盘驱动器被关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文