⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driveinfomain.cpp

📁 检测软驱、CD-ROM、硬盘
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "driveinfomain.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  DWORD dwSize;
  char *lpDrives, *lpItem;

  //Determine how big a buffer is needed to hold all the logical device paths
  dwSize = GetLogicalDriveStrings(0, NULL);
  //Initialize a buffer of the proper size
  lpDrives = new char[dwSize];
  //Get the logical drives
  GetLogicalDriveStrings(dwSize, lpDrives);
  //Initialize a working variable
  lpItem = lpDrives;
  //While there are more items in the list
  //(end of list is indicated by a 0 length string
  while (strlen(lpItem) != 0)
  {
    //Add the current item to the path list
    cbPath->Items->Add(lpItem);
    //Increment the pointer to the next path item in the list
    lpItem += strlen(lpItem) + 1;
  }

  //If there are some logical device paths
  if (cbPath->Items->Count)
  {
    //Make the first item the default
    cbPath->ItemIndex = 0;
    //Load the drive info for the default device path
    GetDriveInfo();
  }

  //Free the memory allocated for the device paths
  delete [] lpDrives;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::cbPathChange(TObject *Sender)
{
  //User changed the combo box selection.  Update the display
  GetDriveInfo();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GetDriveInfo(void)
{
  UINT Type;
  String s;
  char lpVolumeName[255], lpFileSystemName[100], szBuffer[512];
  DWORD dwVolumeSerialNumber, dwMaximumComponentLength, dwFileSystemFlags;

  //Clear the info display
  mInfo->Clear();

  //Get the drive type
  Type = GetDriveType(cbPath->Items->Strings[cbPath->ItemIndex].c_str());
  //Update the display accoring to the drive type
  switch (Type)
  {
    case 0:
      s = "Unknown";
      break;
    case 1:
      s = "Does not exist";
      break;
    case DRIVE_REMOVABLE:
      s = "Removable Disk Drive";
      break;
    case DRIVE_FIXED:
      s = "Fixed Disk Drive";
      break;
    case DRIVE_REMOTE:
      s = "Network Drive";
      break;
    case DRIVE_CDROM:
      s = "CD ROM Drive";
      break;
    case DRIVE_RAMDISK:
      s = "RAM Disk";
  }

  mInfo->Lines->Add("Device Type: " + s);

  //Cjeck the volume information.  Returns TRUE on success
  if (GetVolumeInformation(cbPath->Items->Strings[cbPath->ItemIndex].c_str(),
                           lpVolumeName,
                           255,
                           &dwVolumeSerialNumber,
                           &dwMaximumComponentLength,
                           &dwFileSystemFlags,
                           lpFileSystemName,
                           100))
  {
    //Update the display with the information
    wsprintf(szBuffer, "Volume Name: %s", lpVolumeName);
    mInfo->Lines->Add(szBuffer);
    wsprintf(szBuffer, "Serial Number: %u", dwVolumeSerialNumber);
    mInfo->Lines->Add(szBuffer);
    wsprintf(szBuffer, "File System: %s", lpFileSystemName);
    mInfo->Lines->Add(szBuffer);
  }
  //GetVolumeInformation failed
  else
    //No disk in removable drive or drive not ready
    mInfo->Lines->Add("DRIVE IS NOT READY");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -