For beginners, writing a CD player may be a shortcut to getting started. The core of the CD player is the MCI command, and the articles on how MCI commands are used in various media abound, so I'll skip over them for the moment. Here, I would highlight a more important technique-the support of the multi-drive.
There are often more than one optical drive on people's machines, with ordinary cdrom, CDR, DVDs, and virtual optical drives for the poor:. As a result, programmers who write multimedia software have a problem: how to add support for multiple optical drives in the software. To solve this problem, you first need to learn two API functions to obtain the number of optical drives for the target computer.
GetLogicalDrives ()
The function function is to return a bitmask representing the disk drive of the current variable;
The function prototype is: DWORD getlogicaldrives (VOID);
If the call succeeds, the return value is a bit mask mask that represents the disk drive for the current variable, and the bit position 0 is the drive a,1 for drive b,2 for drive C. If the function call fails, the return value is 0.
For example: If a drive is a, C, D, E on a computer, then the return value of the function call succeeds is 00011101, where the lowest point represents drive A, the bitmask is 1, and because B does not exist, the second-lowest mask is 0.
GetDriveType ()
The function is to obtain the type of a disk drive;
The function prototype is: UINT GetDriveType (LPCTSTR lprootpathname);
Parameter lprootpathname: points to a null-terminated string pointer that specifies the disk root to return information about. If this argument is null, the function uses the current root directory.
Return value: Returns a value that returns the type of the specified drive, which is one of the following values:
DRIVE_UNKNOWN 不能决定驱动器类型
DRIVE_NO_ROOT_DIR 不存在根目录
DRIVE_REMOVABLE 磁盘能从驱动器中删除
DRIVE_FIXED 磁盘不能从驱动器中删除
DRIVE_REMOTE 驱动器是一个远程(网络)驱动器
DRIVE_CDROM 驱动器是一个CDROM驱动器
DRIVE_RAMDISK 驱动器是一个RAM磁盘
For example: Determine if f disk is the optical drive
UINT IsCDRom;
LPCTSTR Drive;
Drive="F:\\";
IsCDRom=GetDriveType(Drive);
if (IsCDRom==DRIVE_CDROM) printf("F盘是光驱");
else printf("F盘不是光驱");
The above is the introduction of two API functions, through the combination of these two functions, we can obtain the number of optical drives.
The following simple to give the source program:
DWORD DriveTemp; LPCTSTR DriveItem;
unsigned short DriveNum=0,itemp;
UINT IsLogicalCDROM;
int CDS=0; //光驱数
DriveTemp=GetLogicalDrives(); //获得磁盘驱动器位掩码
while(DriveTemp)` //获得驱动器数目
{
DriveTemp>>=1;
DriveNum++;
};
for(itemp=4; itemp<=DriveNum;itemp++)
{
switch(itemp)
{
case 4:
DriveItem="D:\\";
break;
case 5:
DriveItem="E:\\";
break;
case 6:
DriveItem="F:\\";
break;
case 7:
DriveItem="G:\\";
break;
...
case 26:
DriveItem="Z:\\";
}
IsLogicalCDROM=GetDriveType(DriveItem);
if (IsLogicalCDROM==DRIVE_CDROM) //获得光驱数目
{
CDName[CDS]=DriveItem;
CDS++;
}
}