📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "mmsystem.h"
#include "math.h"
#include <Registry.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonOKClick(TObject *Sender)
{
//获得CPU的型号
TRegistry *Registry = new TRegistry;
AnsiString strCPU;
try
{
Registry->RootKey=HKEY_LOCAL_MACHINE;
Registry->OpenKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",true);
strCPU=Registry->ReadString("Identifier");
strCPU=strCPU+" "+AnsiString(Registry->ReadInteger("~MHz"))+"MHz";
LabelCPU->Caption=LabelCPU->Caption+strCPU;
}
__finally
{
delete Registry;
}
//获得内存状态
MEMORYSTATUS memory;
//初始化
memory.dwLength =sizeof(memory);
GlobalMemoryStatus(&memory);
LabelMemory->Caption= ("内存:物理内存(Mb):"+AnsiString(int(memory.dwTotalPhys/1024/1024))+ ";其中可用内存是(Mb):"+String(int( memory.dwAvailPhys/1024/1024)));
//获得C盘总空间和C盘可用空间
ULARGE_INTEGER FreeSpaceToCall,TotalSpace,FreeSpace;
::GetDiskFreeSpaceEx("C:",&FreeSpaceToCall, &TotalSpace, &FreeSpace); //获得返回参数
LabelDisk->Caption= ("硬盘:C盘总空间(Mb): "+AnsiString(TotalSpace.QuadPart/1024/1024)+";可用空间(Mb): "+AnsiString(FreeSpace.QuadPart/1024/1024));
// 获得CD-ROM的信息
UINT DiskType;
char DiskName;
for (DiskName ='C'; DiskName <='Z'; DiskName++) //循环检测A~Z
{
//获得磁盘类型
DiskType=GetDriveType((AnsiString(DiskName)+AnsiString(":")).c_str());
if (DiskType ==5)
LabelCD->Caption=LabelCD->Caption+AnsiString(DiskName)+":";
}
//检测光盘是否放入(为讲解简洁,假设已知光驱盘符为F:)
char VolName[255],FileName[100];
DWORD sno,maxl,FileFlag ;
if ((GetVolumeInformation("F:", VolName,255,&sno, &maxl, &FileFlag,FileName,100)))
{
//如果返回值为真
LabelCD->Caption=LabelCD->Caption+"F驱中光盘卷标为:"+AnsiString(VolName)+"光盘序号为:"+AnsiString(sno);
}
else
{
//如果返回值为假
LabelCD->Caption=LabelCD->Caption+"F驱中没有发现光盘";
}
//检测声卡
int WaveDevice,MidiDevice;
WAVEOUTCAPS WaveCap;
MIDIOUTCAPS MidiCap;
WaveDevice=(int)waveOutGetNumDevs(); //波形设备信息
MidiDevice=(int)midiOutGetNumDevs(); // MIDI设备信息
if (WaveDevice==0)
{
LabelWave->Caption="没有发现波形设备";
}
else
{
waveOutGetDevCaps(0,&WaveCap,sizeof(WAVEOUTCAPS));
LabelWave->Caption= LabelWave->Caption+"当前波形设备:"+AnsiString(WaveCap.szPname);
}
if (MidiDevice==0)
LabelWave->Caption= LabelWave->Caption+"\n\n没有发现MIDI设备";
else
{
midiOutGetDevCaps(0,&MidiCap,sizeof(MIDIOUTCAPS));
LabelWave->Caption= LabelWave->Caption+"\n\n 当前MIDI设备:" +AnsiString(MidiCap.szPname);
}
//检测显示器
int tcs;
long bpp,cp,tc;
LabelVideo->Caption=LabelVideo->Caption+"当前分辨率为:"+AnsiString(Screen->Width)+"*"+AnsiString(Screen->Height);
bpp=GetDeviceCaps(Form1->Canvas->Handle ,BITSPIXEL);
tcs=pow(2,bpp); //计算色彩的梯度数
cp= GetDeviceCaps(Form1->Canvas->Handle,PLANES);
tc= pow(tcs,cp); //计算色深
LabelVideo->Caption=LabelVideo->Caption+(";色深为:"+AnsiString(tc));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonCancelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -