WEB开发网
开发学院软件开发汇编语言 实战DeviceIoControl系列之二:获取软盘/硬盘/光盘... 阅读

实战DeviceIoControl系列之二:获取软盘/硬盘/光盘的参数

 2010-01-10 09:37:32 来源:WEB开发网   
核心提示:然后,在 Toolbar的 IDR_MAINFRAME上添加一个按钮,实战DeviceIoControl系列之二:获取软盘/硬盘/光盘的参数(3),ID 为ID_GET_DISK_GEOMETRY,打开 ClassWizard,在 OnGetDiskGeometry 中,添加以下代码const char *szDevN

然后,在 Toolbar的 IDR_MAINFRAME上添加一个按钮,ID 为ID_GET_DISK_GEOMETRY。打开 ClassWizard,在 DiskGeometryView 中添加 ID_GET_DISK_GEOMETRY的映射函数OnGetDiskGeometry。打 开

DiskGeometryView.cpp,包含头文件 GetDiskGeometry.h。 

在 OnGetDiskGeometry 中,添加以下代码 

const char *szDevName[]=
   {
     ".A:",
    ".B:",
    ".PhysicalDrive0",
    ".PhysicalDrive1",
    ".PhysicalDrive2",
     ".PhysicalDrive3",
    ".Cdrom0",
     ".Cdrom1",
  };
  DISK_GEOMETRY dg;
  ULONGLONG DiskSize;
  BOOL bResult;   CString strMsg;
  CString strTmp;

  for (int i = 0; i < sizeof(szDevName)/sizeof(char*); i++)
  {
    bResult = GetDriveGeometry(szDevName[i], &dg);

    strTmp.Format("rn%s  result = %srn", szDevName[i], bResult ?
"success" : "failure");
    strMsg+=strTmp;

    if (!bResult) continue;

    strTmp.Format("  Media Type = %drn", dg.MediaType);
    strMsg+=strTmp;

    strTmp.Format("   Cylinders = %I64drn", dg.Cylinders);
    strMsg+=strTmp;

     strTmp.Format("  Tracks per cylinder = %ldrn", (ULONG)
dg.TracksPerCylinder);
    strMsg+=strTmp;

    strTmp.Format ("  Sectors per track = %ldrn", (ULONG)
dg.SectorsPerTrack);
     strMsg+=strTmp;

    strTmp.Format("  Bytes per sector = %ldrn", (ULONG)
dg.BytesPerSector);     strMsg+=strTmp;

    DiskSize = dg.Cylinders.QuadPart * (ULONG)dg.TracksPerCylinder
*
      (ULONG) dg.SectorsPerTrack * (ULONG)dg.BytesPerSector;
    strTmp.Format("  Disk size = %I64d (Bytes) = %I64d (Mb)rn",
DiskSize, DiskSize / (1024 * 1024));
    strMsg+=strTmp;
  }

  CEdit& Edit = GetEditCtrl();

  Edit.SetWindowText(strMsg);

最后,最后干什么呢?编译,运行......

上一页  1 2 3 

Tags:实战 DeviceIoControl 系列

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接