windows98에서는 GetFreeSystemResources로
GDIResources 와 UserResources를 구했는데...
windows2000에서는 안되더군요.. ㅜㅜ
방법을 아시는 분은 가까운 경찰서, 아니 ㅡㅡ;; 답변좀 올려주세요...
꼭 좀..부탁드립니다.
procedure TForm1.Button1Click(Sender: TObject);
var
Memory :TMemory;
begin
Memory := TMemory.Create;
Memory.GetInfo;
ListBox.Items.Add(Format('Memory: %d MB (%d KB free)',[Memory.PhysicalTotal div 1024 div 1024,Memory.PhysicalFree div 1024]));
end;
-그리고 MSI_Memory.PAS를 만들어 아래것을 복사하세요
만들고 프로젝트에 포함하셔야합니다.
unit MSI_Memory;
interface
uses
SysUtils, Windows, Classes;
type
TMemoryStatusEx = record
dwLength,
dwMemoryLoad: DWORD;
ullTotalPhys,
ullAvailPhys,
ullTotalPageFile,
ullAvailPageFile,
ullTotalVirtual,
ullAvailVirtual,
ullAvailExtendedVirtual: int64;
end;
function TMemory.GetGDIRes: Byte;
begin
{$IFDEF ONLYWIN9X}
Result:=GetFreeSysRes(cGDI)
{$ELSE}
Result:=0;
{$ENDIF}
end;
function TMemory.GetSystemRes: Byte;
begin
{$IFDEF ONLYWIN9X}
Result:=GetFreeSysRes(cSystem)
{$ELSE}
Result:=0;
{$ENDIF}
end;
function TMemory.GetUSERRes: Byte;
begin
{$IFDEF ONLYWIN9X}
Result:=GetFreeSysRes(cUser)
{$ELSE}
Result:=0;
{$ENDIF}
end;
constructor TMemory.Create;
begin
@_GlobalMemoryStatusEx:=GetProcAddress(GetModuleHandle('kernel32'),PChar('GlobalMemoryStatusEx'));
end;
procedure TMemory.GetInfo;
var
SI :TSystemInfo;
MS :TMemoryStatus;
MSEX :TMemoryStatusEx;
begin
ZeroMemory(@MSEX,SizeOf(MSEX));
MSEX.dwLength:=SizeOf(MSEX);
GlobalMemoryStatusEx(@MSEX);
FMemoryLoad:=MSEX.dwMemoryLoad;
FPhysicalTotal:=MSEX.ullTotalPhys;
FPhysicalFree:=MSEX.ullAvailPhys;
FVirtualTotal:=MSEX.ullTotalVirtual;
FVirtualFree:=MSEX.ullAvailVirtual;
FPageFileTotal:=MSEX.ullTotalPageFile;
FPageFileFree:=MSEX.ullAvailPageFile;
ZeroMemory(@SI,SizeOf(SI));
GetSystemInfo(SI);
FAllocGranularity:=SI.dwAllocationGranularity;
FMaxAppAddress:=DWORD(SI.lpMaximumApplicationAddress);
FMinAppAddress:=DWORD(SI.lpMinimumApplicationAddress);
FPageSize:=DWORD(SI.dwPageSize);
FSystemRes:=GetSystemRes;
FGDIRes:=GetGDIRes;
FUserRes:=GetUserRes;
end;
function GlobalMemoryStatusEx;
begin
if Assigned(_GlobalMemoryStatusEx) then
Result:=_GlobalMemoryStatusEx(lpBuffer)
else
Result:=False;
end;
windows98에서는 GetFreeSystemResources로 GDIResources 와 UserResources를 구했는데... windows2000에서는 안되더군요.. ㅜㅜ 방법을 아시는 분은 가까운 경찰서, 아니 ㅡㅡ;; 답변좀 올려주세요... 꼭 좀..부탁드립니다.
홍성락
•
2002.03.20 19:48
hsr////////////////////////////////////////////////////////////////
하드웨어 리소스중 메모리관련된...
하드웨어 리소스중 메모리관련된것을 2가지로 해보았습니다.
1방법은 팁에 많은 분들이 올리신거구요
var
MemStat : TMemoryStatus;
begin
MemStat.dwLength := sizeof(TMemoryStatus);
GlobalMemoryStatus(MemStat);
with MemStat do begin
Label1.Caption := Format('%d KB',[Trunc(dwTotalPhys/1024)]); //총메모리
Label2.Caption := Format('%d KB',[Trunc(dwAvailPhys/1024)]); //MemAvailable
Label3.Caption := Format('%d %%',[trunc(dwAvailPhys/dwTotalPhys*100)]); //사용메모리
Label4.Caption := Format('%d KB',[Trunc(dwTotalPageFile/1024)]); //SwapFileSetting
Label5.Caption := Format('%d KB',[Trunc((dwTotalPageFile-dwAvailPageFile)/1024)]); //SwapFileSize
Label6.Caption := Format('%d %%',[100-trunc(dwAvailPageFile/dwTotalPageFile*100)]); //SwapFileUsage
end;
end;
//-----------------------------------------------------------------
2방법은 MiTeC 컴포넌트중 부분적사용으로 만드는겁니다.
-먼저 사용방법은 유닛에 MSI_Memory를 추가선언하구요
사용방법은 아래와 같습니다
procedure TForm1.Button1Click(Sender: TObject);
var
Memory :TMemory;
begin
Memory := TMemory.Create;
Memory.GetInfo;
ListBox.Items.Add(Format('Memory: %d MB (%d KB free)',[Memory.PhysicalTotal div 1024 div 1024,Memory.PhysicalFree div 1024]));
end;
-그리고 MSI_Memory.PAS를 만들어 아래것을 복사하세요
만들고 프로젝트에 포함하셔야합니다.
unit MSI_Memory;
interface
uses
SysUtils, Windows, Classes;
type
TMemoryStatusEx = record
dwLength,
dwMemoryLoad: DWORD;
ullTotalPhys,
ullAvailPhys,
ullTotalPageFile,
ullAvailPageFile,
ullTotalVirtual,
ullAvailVirtual,
ullAvailExtendedVirtual: int64;
end;
PMemoryStatusEx = ^TMemoryStatusEx;
TMemory = class(TPersistent)
private
FMaxAppAddress: integer;
FVirtualTotal: int64;
FPageFileFree: Int64;
FVirtualFree: int64;
FPhysicalFree: int64;
FAllocGranularity: integer;
FMinAppAddress: integer;
FMemoryLoad: integer;
FPhysicalTotal: int64;
FPageFileTotal: int64;
FPageSize: integer;
FGDIRes: Byte;
FUserRes: Byte;
FSystemRes: Byte;
function GetSystemRes: Byte;
function GetGDIRes: Byte;
function GetUSERRes: Byte;
public
constructor Create;
procedure GetInfo;
published
property PhysicalTotal :int64 read FPhysicalTotal {$IFNDEF D6PLUS} write FPhysicalTotal {$ENDIF} stored false;
property PhysicalFree :int64 read FPhysicalFree {$IFNDEF D6PLUS} write FPhysicalFree {$ENDIF} stored false;
property VirtualTotal :int64 read FVirtualTotal {$IFNDEF D6PLUS} write FVirtualTotal {$ENDIF} stored false;
property VirtualFree :int64 read FVirtualFree {$IFNDEF D6PLUS} write FVirtualFree {$ENDIF} stored false;
property PageFileTotal :int64 read FPageFileTotal {$IFNDEF D6PLUS} write FPageFileTotal {$ENDIF} stored false;
property PageFileFree :int64 read FPageFileFree {$IFNDEF D6PLUS} write FPageFileFree {$ENDIF} stored false;
property MemoryLoad :integer read FMemoryLoad {$IFNDEF D6PLUS} write FMemoryLoad {$ENDIF} stored false;
property AllocGranularity :integer read FAllocGranularity {$IFNDEF D6PLUS} write FAllocGranularity {$ENDIF} stored false;
property MaxAppAddress :integer read FMaxAppAddress {$IFNDEF D6PLUS} write FMaxAppAddress {$ENDIF} stored false;
property MinAppAddress :integer read FMinAppAddress {$IFNDEF D6PLUS} write FMinAppAddress {$ENDIF} stored false;
property PageSize :integer read FPageSize {$IFNDEF D6PLUS} write FPageSize {$ENDIF} stored false;
// if you want to get these values you must change conditional define ONLYWIN9X in MiTeC_Def.inc
property Win9x_SystemRes: Byte read FSystemRes {$IFNDEF D6PLUS} write FSystemRes {$ENDIF} stored false;
property Win9x_GDIRes: Byte read FGDIRes {$IFNDEF D6PLUS} write FGDIRes {$ENDIF} stored false;
property Win9x_UserRes: Byte read FUserRes {$IFNDEF D6PLUS} write FUserRes {$ENDIF} stored false;
end;
type
TGlobalMemoryStatusEx = function(lpBuffer: PMEMORYSTATUSEX): BOOL; stdcall;
function GlobalMemoryStatusEx(lpBuffer: PMEMORYSTATUSEX): BOOL; stdcall;
implementation
//uses MiTeC_Routines;
var
_GlobalMemoryStatusEx: TGlobalMemoryStatusEx;
{$IFDEF ONLYWIN9X}
const
cSystem = 0;
cGDI = 1;
cUSER = 2;
var
hInst16: THandle;
SR: Pointer;
{$ENDIF}
function TMemory.GetGDIRes: Byte;
begin
{$IFDEF ONLYWIN9X}
Result:=GetFreeSysRes(cGDI)
{$ELSE}
Result:=0;
{$ENDIF}
end;
function TMemory.GetSystemRes: Byte;
begin
{$IFDEF ONLYWIN9X}
Result:=GetFreeSysRes(cSystem)
{$ELSE}
Result:=0;
{$ENDIF}
end;
function TMemory.GetUSERRes: Byte;
begin
{$IFDEF ONLYWIN9X}
Result:=GetFreeSysRes(cUser)
{$ELSE}
Result:=0;
{$ENDIF}
end;
constructor TMemory.Create;
begin
@_GlobalMemoryStatusEx:=GetProcAddress(GetModuleHandle('kernel32'),PChar('GlobalMemoryStatusEx'));
end;
procedure TMemory.GetInfo;
var
SI :TSystemInfo;
MS :TMemoryStatus;
MSEX :TMemoryStatusEx;
begin
ZeroMemory(@MSEX,SizeOf(MSEX));
MSEX.dwLength:=SizeOf(MSEX);
GlobalMemoryStatusEx(@MSEX);
FMemoryLoad:=MSEX.dwMemoryLoad;
FPhysicalTotal:=MSEX.ullTotalPhys;
FPhysicalFree:=MSEX.ullAvailPhys;
FVirtualTotal:=MSEX.ullTotalVirtual;
FVirtualFree:=MSEX.ullAvailVirtual;
FPageFileTotal:=MSEX.ullTotalPageFile;
FPageFileFree:=MSEX.ullAvailPageFile;
ZeroMemory(@SI,SizeOf(SI));
GetSystemInfo(SI);
FAllocGranularity:=SI.dwAllocationGranularity;
FMaxAppAddress:=DWORD(SI.lpMaximumApplicationAddress);
FMinAppAddress:=DWORD(SI.lpMinimumApplicationAddress);
FPageSize:=DWORD(SI.dwPageSize);
FSystemRes:=GetSystemRes;
FGDIRes:=GetGDIRes;
FUserRes:=GetUserRes;
end;
function GlobalMemoryStatusEx;
begin
if Assigned(_GlobalMemoryStatusEx) then
Result:=_GlobalMemoryStatusEx(lpBuffer)
else
Result:=False;
end;
end.