直升机,
我一直在测试一个检测CD / DVD版insertion/removal的c ++代码。 我测试的代码非常适合检测CD / DVD的插入/删除。
但是我想扩展此代码以检测启动期间CD / DVD托盘中是否已有印版。任何想法我如何扩展此代码以在启动期间检查这个?我到目前为止测试的代码如下:
char FirstDriveFromMask(ULONG unitmask)
{
char i;
for (i = 0; i < 26; ++i)
{
if (unitmask & 0x1)
break;
unitmask = unitmask >> 1;
}
//cout << "dd" << (i + 'A');
return(i + 'A');
}
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
TCHAR szMsg[80];
switch (wParam)
{
case DBT_DEVICEARRIVAL:
// Check whether a CD or DVD was inserted into a drive.
if (lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
//check which letter is the new device
if (lpdbv->dbcv_flags & DBTF_MEDIA)
{
cout << "CD/DVD has been inserted in: " << FirstDriveFromMask(lpdbv->dbcv_unitmask) <<" drive"<<endl;
}
}
break;
case DBT_DEVICEREMOVECOMPLETE:
// Check whether a CD or DVD was removed from a drive.
if (lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
if (lpdbv->dbcv_flags & DBTF_MEDIA)
{
cout << "CD/DVD has been removed from: " << FirstDriveFromMask(lpdbv->dbcv_unitmask) << " drive" << endl;
}
}
break;
default:
/*
Process other WM_DEVICECHANGE notifications for other
devices or reasons.
*/
;
}
return 1;
}//WinProc