用Delphi如何得到物理内存的大小? 不是剩余内存 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用globalmemorystatusunit unitFrmMain;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);var MemInfo: MEMORYSTATUS;begin // 获取内存信息 GlobalMemoryStatus(MemInfo); Memo1.Lines.Add(IntToStr(MemInfo.dwMemoryLoad) + '%的内存在使用'); Memo1.Lines.Add('物理内存共有' + IntToStr(MemInfo.dwTotalPhys) + '字节'); Memo1.Lines.Add('未使用的物理内存有' + IntToStr(MemInfo.dwAvailPhys) + '字节'); Memo1.Lines.Add('交换文件的大小为' + IntToStr(MemInfo.dwTotalPageFile) + '字节'); Memo1.Lines.Add('未使用的交换文件大小为' + IntToStr(MemInfo.dwAvailPageFile) + '字节'); Memo1.Lines.Add('虚拟内存空间大小为' + IntToStr(MemInfo.dwTotalVirtual) + '字节'); Memo1.Lines.Add('未使用的虚拟内存大小为' + IntToStr(MemInfo.dwAvailVirtual) + '字节');end; procedure Tform1.timer1timer(sender:Tobject);var TMS:TMemoryStatus;begin TMS.dwLength:=sizeof(TMS); GlobalMemorystatus(TMS); gauge1.progress:=TMS.dwMemoryLoad; gauge1.progress:=(100*TMS.dwAvailphys) div TMS.dwtotalphys; gauge1.progress:=(100*TMS.dwavailpagefile)div tms.dwtotalpagefile;end; TMS结构说明: dwlength 该结构的长度 dwmemoryload 内存使用百分比 dwtotalphys 实际内存总字节数 dwavailphys 用的实际内存总字节数 dwtotalpagefile 分页文件总字节数 dwavailpagefile 分页文件可用字节数 dwtotalvirtual 虚拟内存的总字节数。 dwavailvirtual 可用的虚拟内存字节数 这是一个程序里面的代码,可以取得一些系统信息,应该对你有用procedure TForm1.Button1Click(Sender: TObject);var systeminfo: SYSTEM_INFO; memory: MEMORYSTATUS; sector,byte,cluster,free: DWORD; freespace,totalspace: longint; CDtype: UINT; name: CHAR; drvname: string; volname,filesysname: PCHAR; sno,maxl,fileflag: DWORD;begin Memo1.Lines.Clear(); //获得CPU型号 GetSystemInfo(systeminfo); Memo1.Lines.Add('您的CPU类型是:' + inttostr(systeminfo.dwProcessorType)); //获得内存状态 memory.dwLength := sizeof(memory); //初始化 GlobalMemoryStatus(memory); Memo1.Lines.Add('您的物理内存是(' + inttostr(integer(memory.dwTotalPhys div 1024 div 1024)) + 'MB)。'); Memo1.Lines.Add('其中可用内存是(' + inttostr(integer(memory.dwTotalPhys div 1024)) + 'KB)。'); //获得C盘可用空间 GetDiskFreeSpace('C:', LPDWORD(@sector)^, LPDWORD(@byte)^, LPDWORD(@free)^, LPDWORD(@cluster)^); //获得返回参数 totalspace := cluster * byte * sector div 1024 div 1024; //计算总容量 freespace := free * byte * sector div 1024 div 1024; //计算可用空间 Memo1.Lines.Add('C盘总空间(' + inttostr(integer(totalspace)) + 'MB)。'); Memo1.Lines.Add('C盘可用空间(' + inttostr(integer(freespace)) + 'MB)。'); //检测CD-ROM,是否有光盘 GetMem(volname, 255); GetMem(filesysname, 100); for name :='C' to 'Z' do//循环检测A~Z begin drvname := name + ':'; CDtype := GetDriveType(PCHAR(@drvname[1])); //获得磁盘类型 if (CDtype = DRIVE_CDROM) then begin Memo1.Lines.Add('您的光驱盘符为[' + drvname + ']'); volname^ := Chr(0); filesysname^ := Chr(0); if ( not (GetVolumeInformation(PCHAR(@drvname[1]), volname, 250, LPDWORD(@sno), LPDWORD(@maxl)^, LPDWORD(@fileflag)^, filesysname,100))) then Memo1.Lines.Add(drvname + '驱中没有发现光盘') //如果返回值为假 else //如果返回值为真 begin Memo1.Lines.Add (drvname + '驱中光盘卷标为: [' + String(volname) + ']'); Memo1.Lines.Add (drvname + '驱中光盘序号为: [' + inttostr(sno) + ']'); end; end; end; FreeMem(volname); FreeMem(filesysname)end; ImageENview载入TIF图片后,图片显示会变扁,请教如何解决 如何向Dll窗体中传递参数 file not found"FR_Desgn.dcu"该怎么处理? 我怎么写数据库的配置文件啊?? 高分求救!中间层创建线程服务客户端! OnHelp的问题 菜鸟求学~~~ 保存地址的问题,来帮帮我把 请教ACCESS数据库和DBF的数据库加密的问题!UP有分 关于用ICS下载文件的文件保存问题 一 COM/DOCOM 程序,运行报“RPC服务器不可用”错误?不知为何。 怎么获得打印页边据
unit unitFrmMain;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var MemInfo: MEMORYSTATUS;
begin
// 获取内存信息
GlobalMemoryStatus(MemInfo);
Memo1.Lines.Add(IntToStr(MemInfo.dwMemoryLoad) + '%的内存在使用');
Memo1.Lines.Add('物理内存共有' + IntToStr(MemInfo.dwTotalPhys) + '字节');
Memo1.Lines.Add('未使用的物理内存有' + IntToStr(MemInfo.dwAvailPhys) + '字节');
Memo1.Lines.Add('交换文件的大小为' + IntToStr(MemInfo.dwTotalPageFile) + '字节');
Memo1.Lines.Add('未使用的交换文件大小为' + IntToStr(MemInfo.dwAvailPageFile) + '字节');
Memo1.Lines.Add('虚拟内存空间大小为' + IntToStr(MemInfo.dwTotalVirtual) + '字节');
Memo1.Lines.Add('未使用的虚拟内存大小为' + IntToStr(MemInfo.dwAvailVirtual) + '字节');
end;
var
TMS:TMemoryStatus;
begin
TMS.dwLength:=sizeof(TMS);
GlobalMemorystatus(TMS);
gauge1.progress:=TMS.dwMemoryLoad;
gauge1.progress:=(100*TMS.dwAvailphys) div TMS.dwtotalphys;
gauge1.progress:=(100*TMS.dwavailpagefile)div tms.dwtotalpagefile;
end;
TMS结构说明:
dwlength 该结构的长度
dwmemoryload 内存使用百分比
dwtotalphys 实际内存总字节数
dwavailphys 用的实际内存总字节数
dwtotalpagefile 分页文件总字节数
dwavailpagefile 分页文件可用字节数
dwtotalvirtual 虚拟内存的总字节数。
dwavailvirtual 可用的虚拟内存字节数
procedure TForm1.Button1Click(Sender: TObject);
var
systeminfo: SYSTEM_INFO;
memory: MEMORYSTATUS;
sector,byte,cluster,free: DWORD;
freespace,totalspace: longint;
CDtype: UINT;
name: CHAR;
drvname: string;
volname,filesysname: PCHAR;
sno,maxl,fileflag: DWORD;
begin
Memo1.Lines.Clear();
//获得CPU型号
GetSystemInfo(systeminfo);
Memo1.Lines.Add('您的CPU类型是:' + inttostr(systeminfo.dwProcessorType)); //获得内存状态
memory.dwLength := sizeof(memory); //初始化
GlobalMemoryStatus(memory);
Memo1.Lines.Add('您的物理内存是(' + inttostr(integer(memory.dwTotalPhys div 1024 div 1024)) + 'MB)。');
Memo1.Lines.Add('其中可用内存是(' + inttostr(integer(memory.dwTotalPhys div 1024)) + 'KB)。'); //获得C盘可用空间
GetDiskFreeSpace('C:', LPDWORD(@sector)^, LPDWORD(@byte)^, LPDWORD(@free)^, LPDWORD(@cluster)^); //获得返回参数
totalspace := cluster * byte * sector div 1024 div 1024; //计算总容量
freespace := free * byte * sector div 1024 div 1024; //计算可用空间
Memo1.Lines.Add('C盘总空间(' + inttostr(integer(totalspace)) + 'MB)。');
Memo1.Lines.Add('C盘可用空间(' + inttostr(integer(freespace)) + 'MB)。'); //检测CD-ROM,是否有光盘
GetMem(volname, 255);
GetMem(filesysname, 100);
for name :='C' to 'Z' do//循环检测A~Z
begin
drvname := name + ':';
CDtype := GetDriveType(PCHAR(@drvname[1])); //获得磁盘类型
if (CDtype = DRIVE_CDROM) then
begin
Memo1.Lines.Add('您的光驱盘符为[' + drvname + ']');
volname^ := Chr(0);
filesysname^ := Chr(0);
if ( not (GetVolumeInformation(PCHAR(@drvname[1]), volname, 250, LPDWORD(@sno), LPDWORD(@maxl)^, LPDWORD(@fileflag)^, filesysname,100))) then
Memo1.Lines.Add(drvname + '驱中没有发现光盘') //如果返回值为假
else //如果返回值为真
begin
Memo1.Lines.Add (drvname + '驱中光盘卷标为: [' + String(volname) + ']');
Memo1.Lines.Add (drvname + '驱中光盘序号为: [' + inttostr(sno) + ']');
end;
end;
end;
FreeMem(volname);
FreeMem(filesysname)
end;