void ctrl_cdrom_door(
LPCTSTR drivename ,//光驱的盘符,如f:等.
bool fOpen//弹出时用true,弹入时用false
)
{
TCHAR devstr[128],ctrlstr[128];
wsprintf(devstr,_T("open %s type cdaudio alias mycd wait"),drivename);
wsprintf(ctrlstr,_T("set mycd door %s wait"),fOpen?_T("open"):_T("closed"));
mciSendString(devstr,NULL,0,NULL);
mciSendString(ctrlstr,NULL,0,NULL);
mciSendString(_T("close mycd wait"),NULL,0,NULL);
}
ctrl_cdrom_door("L:",true); //打开光驱
ctrl_cdrom_door("L:",false); //关闭光驱
这个是打开指定盘符的,在上面的基础上,下面的可以打开第几个光驱,不用指定光驱盘符
void Cdopen(int cdn) //打开第cdn个光驱
{
// TODO: Add your control notification handler code here
int i,cdnum=0;
char str[3];
for(i=0;i<10;i++)
{
str[0]='A'+i;
str[1]=':';
str[2]='\0';
if(DRIVE_CDROM==GetDriveType(str))
cdnum++;
if(cdnum==cdn)
{
ctrl_cdrom_door(str,true); //打开光驱
break;
}
}
}
void Cdclose(int cdn) //关闭第cdn个光驱
{
// TODO: Add your control notification handler code here
int i,cdnum=0;
char str[3];
for(i=0;i<10;i++)
{
str[0]='A'+i;
str[1]=':';
str[2]='\0';
if(DRIVE_CDROM==GetDriveType(str))
cdnum++;
if(cdnum==cdn)
{
ctrl_cdrom_door(str,false); //关闭光驱
break;
}
}
}