求助!究竟哪里错了?
这是基于对话框创建的程序,目的是控制光驱的开关。两个按钮,一个开,一个关。Button1控制开,Button2控制关。结果是可以开,但是不能关。究竟哪里出了问题啊!代码如下:
void CffDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
MCI_OPEN_PARMS op;
MCI_STATUS_PARMS st;
DWORD flags;
TCHAR szDriveName[4] = _T("G:");
op.lpstrDeviceType = (LPCWSTR) MCI_DEVTYPE_CD_AUDIO;
op.lpstrElementName = szDriveName;
flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE;
if( !mciSendCommand(0,MCI_OPEN,flags,(unsigned long)&op) )
{
st.dwItem = MCI_STATUS_READY;
mciSendCommand(op.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0);
}
}
void CffDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
MCI_OPEN_PARMS op;
MCI_STATUS_PARMS st;
DWORD flags;
TCHAR szDriveName[4] = _T("G:");
op.lpstrDeviceType = (LPCWSTR) MCI_DEVTYPE_CD_AUDIO;
op.lpstrElementName = szDriveName;
flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE;
if( !mciSendCommand(0,MCI_OPEN,flags,(unsigned long)&op) )
{
st.dwItem = MCI_STATUS_READY;
mciSendCommand(op.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);
}
}