Dùng thử đoạn code sau, lục trong Howto của tui:
Code:
14/. How can detect if there's a floppy in the disk drive?
You can call the GetVolumeInformation() API to find out whether there's a
disk in a particular drive or not. Keep in mind to set the error mode to
SEM_FAILCRITICALERRORS before doing it, otherwise, the standard "Drive Not
Ready" dialog will pop up. Here's a short example:
BOOL IsDiskInDrive(LPTSTR lpszDrive)
{
UINT errMode;
TCHAR szVolName[256];
DWORD dwMaxComSize;
DWORD dwFlags;
TCHAR szFS[256];
BOOL bRet;
errMode = SetErrorMode(SEM_FAILCRITICALERRORS);
bRet = GetVolumeInformation(lpszDrive, szVolName, sizeof(szVolName),
NULL, &dwMaxComSize, &dwFlags,
szFS, sizeof(szFS));
SetErrorMode(errMode);
return bRet;
}
This technique should also work for CD-ROM drives and other removable media