请问如何设置CFileDialog打开时的目录为本地物理光驱的根目录 分两步回答吧 第一个如何得到光驱的盘符第二个如何改File open的目录 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 2. CFileDialog dlg(TRUE); dlg.m_ofn.lpstrInitialDir = "F:\\光盘路径"; //光盘路径 dlg.DoModal(); GetDriveType("D:") == DRIVE_CDROM 判断是否为光驱 以下是遍历驱动器,取各个驱动器属性的函数,驱动器类型为DRIVE_CDROM的是光驱。int FillPacket_drivers(CBuffer *pBuffer){ int DriveType; char drivers[160]; char FreeByteChar[100], TotalByteChar[100]; __int64 fulldisk; DWORD SectorsPerCluster, BytesPerSectors, FreeCluster, TotalCluster; __int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; drivers[0] = 0; fulldisk = 0; if(GetLogicalDriveStrings(sizeof(drivers), drivers) >0) { char *p = drivers; while(*p) { pBuffer->Format(" %s\t%-20s", p, cv_drivetype(p, &DriveType)); if( (DriveType == DRIVE_FIXED) && GetDiskFreeSpace(p, &SectorsPerCluster, &BytesPerSectors, &FreeCluster, &TotalCluster) && GetDiskFreeSpaceEx(p, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes) ) { fulldisk += i64TotalBytes; i64FreeBytes /= 1024; i64TotalBytes /= 1024; pBuffer->Format("%d S/C %d B/S Free %-10s KB, Total %-10s KB", SectorsPerCluster, BytesPerSectors, cv_s_int64u(i64FreeBytes, FreeByteChar, sizeof(FreeByteChar)), cv_s_int64u(i64TotalBytes,TotalByteChar, sizeof(TotalByteChar)) ); } pBuffer->Format("\r\n"); p += strlen(p) + 1; // } fulldisk /= 1024 ; pBuffer->Format("\t\t\tTotal Disk %s KB\r\n", cv_s_int64u(fulldisk, TotalByteChar, sizeof(TotalByteChar)) ); } return pBuffer->GetBufferLen();}设置打开路径如下:CFileDialog dlg(TRUE, ...);dlg.m_ofn.lpstrInitialDir = "G:\\"; //G为光盘盘符 for(char ch='A';ch<'Z';ch++){ CString str; str.Format("%c:",ch); if(GetDriveType(str) == DRIVE_CDROM) { CFileDialog dlg(TRUE); dlg.m_ofn.lpstrInitialDir =str; dlg.DoModal(); break; }} MFC写如何用C++写密码验证程序? 无损图像如何采集? openssl中libeay32.lib怎么静态链接? 哪儿有《MFC程序设计Using Visual C++ 6.0》下载啊?? 如何将BYTE型转换为int型 有关<<深入浅出MFC>>的问题 把几个DIALOG加到一起的那个类叫什么 MFC ActiveX控件的问题,很急 如何修改框架? msflexgrid控件中如何使一行或一列处于被选中的状态(这一行的颜色应该区别与其他行) 如何实现类似于VC对话框编辑器的容器功能,比如说: 急!ADO怎么搞的
CFileDialog dlg(TRUE);
dlg.m_ofn.lpstrInitialDir = "F:\\光盘路径"; //光盘路径
dlg.DoModal();
判断是否为光驱
{
int DriveType;
char drivers[160];
char FreeByteChar[100], TotalByteChar[100];
__int64 fulldisk;
DWORD SectorsPerCluster, BytesPerSectors, FreeCluster, TotalCluster;
__int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; drivers[0] = 0;
fulldisk = 0;
if(GetLogicalDriveStrings(sizeof(drivers), drivers) >0)
{
char *p = drivers;
while(*p)
{
pBuffer->Format(" %s\t%-20s", p, cv_drivetype(p, &DriveType));
if( (DriveType == DRIVE_FIXED) &&
GetDiskFreeSpace(p, &SectorsPerCluster, &BytesPerSectors, &FreeCluster, &TotalCluster) &&
GetDiskFreeSpaceEx(p, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes) )
{
fulldisk += i64TotalBytes; i64FreeBytes /= 1024;
i64TotalBytes /= 1024; pBuffer->Format("%d S/C %d B/S Free %-10s KB, Total %-10s KB",
SectorsPerCluster,
BytesPerSectors,
cv_s_int64u(i64FreeBytes, FreeByteChar, sizeof(FreeByteChar)),
cv_s_int64u(i64TotalBytes,TotalByteChar, sizeof(TotalByteChar)) );
}
pBuffer->Format("\r\n");
p += strlen(p) + 1; //
} fulldisk /= 1024 ;
pBuffer->Format("\t\t\tTotal Disk %s KB\r\n", cv_s_int64u(fulldisk, TotalByteChar, sizeof(TotalByteChar)) );
}
return pBuffer->GetBufferLen();
}设置打开路径如下:
CFileDialog dlg(TRUE, ...);
dlg.m_ofn.lpstrInitialDir = "G:\\"; //G为光盘盘符
{
CString str;
str.Format("%c:",ch);
if(GetDriveType(str) == DRIVE_CDROM)
{
CFileDialog dlg(TRUE);
dlg.m_ofn.lpstrInitialDir =str;
dlg.DoModal();
break;
}
}