Kod:
Cpu Usage gibi pek çok hafıza elemanın görüntüleyebilirsiniz
//---------------------------------------------------------------------------
#ifndef mktMemInfoH
#define mktMemInfoH
#define mktCpuUsage 0
#define mktTotalPhysicalMemory 1
#define mktAvailPhysicalMemory 2
#define mktTotalVirtualMemory 3
#define mktAvailVirtualMemory 4
#define mktTotalPageFileMemory 5
#define mktAvailPageFileMemory 6
#define mktTotalPhysicalMemory 7
#define mktMemoryLoad 8
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <perfgrap.h>
#include <ExtCtrls.hpp>
#include <windows.h>
#include <stdio.h>
#include "mktCpuUsage.h"
//---------------------------------------------------------------------------
class mktMemInfo
{
private:
TForm * mktForm;
TPanel * mktPanel;
TLabel * mktLabel;
TPerformanceGraph * PG;
TTimer * mktTimer;
int _monitor;
CCpuUsage * Cpu;
__int64 TotalPhysicalMemory(****){
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
return ms.dwTotalPhys;
}
__int64 AvailPhysicalMemory(****){
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
return ms.dwAvailPhys;
}
__int64 TotalVirtualMemory(****){
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
return ms.dwTotalVirtual;
}
__int64 AvailVirtualMemory(****){
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
return ms.dwAvailVirtual;
}
__int64 TotalPageFileMemory(****){
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
return ms.dwTotalPageFile;
}
__int64 AvailPageFileMemory(****){
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
return ms.dwAvailPageFile;
}
__int64 MemoryLoad(****){
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
return ms.dwMemoryLoad / 2;
}
**** __fastcall mktTimerOn(TObject *Sender)
{
if(_monitor == mktTotalPhysicalMemory )
{
__int64 a=0;
a = TotalPhysicalMemory()/1024;
PG->DataPoint(clRed,a);
PG->Update();
mktLabel->Caption = "Total Physical Memory: "+FormatFloat("##,00",a)+" kb";
}
if(_monitor == mktAvailPhysicalMemory )
{
__int64 a=0;
a = AvailPhysicalMemory()/1024;
PG->DataPoint(clRed,a);
PG->Update();
mktLabel->Caption = "Avail Physical Memory: "+FormatFloat("##,00",a)+" kb";
}
if(_monitor == mktTotalVirtualMemory )
{
__int64 a=0;
a = TotalVirtualMemory()/1024;
PG->DataPoint(clRed,a);
PG->Update();
mktLabel->Caption = "Total Virtual Memory: "+FormatFloat("##,00",a)+" kb";
}
if(_monitor == mktAvailVirtualMemory )
{
__int64 a=0;
a = AvailVirtualMemory()/1024;
PG->DataPoint(clRed,a);
PG->Update();
mktLabel->Caption = "Avail Virtual Memory: "+FormatFloat("##,00",a)+" kb";
}
if(_monitor == mktTotalPageFileMemory )
{
__int64 a=0;
a = TotalPageFileMemory()/1024;
PG->DataPoint(clRed,a);
PG->Update();
mktLabel->Caption = "Total Page File Memory: "+FormatFloat("##,00",a)+" kb";
}
if(_monitor == mktAvailPageFileMemory )
{
__int64 a=0;
a = AvailPageFileMemory()/1024;
PG->DataPoint(clRed,a);
PG->Update();
mktLabel->Caption = "Avail Page File Memory: "+FormatFloat("##,00",a)+" kb";
}
if(_monitor == mktMemoryLoad )
{
__int64 a=0;
a = MemoryLoad();
PG->DataPoint(clRed,a);
PG->Update();
mktLabel->Caption = "Memory Load: %"+FormatFloat("##,00",a);
}
if(_monitor == mktCpuUsage )
{
int a=0;
a = Cpu->GetCpuUsage();
PG->DataPoint(clRed,a);
PG->Update();
mktLabel->Caption = "Cpu Usage Index: %"+FormatFloat("##,00",a);
}
}
protected:
int f1(){return mktTimer->Interval;}
**** f2(int value){mktTimer->Interval = value;}
bool f3(){return mktTimer->Enabled;}
**** f4(bool value){mktTimer->Enabled = value;}
AnsiString f5(){return mktLabel->Caption;}
**** f6(AnsiString value){mktLabel->Caption = value;}
int f7(){return _monitor;}
**** f8(int value){_monitor=value;}
public:
__property int Interval = {read=f1,write=f2};
__property bool Active = {read=f3, write=f4};
__property AnsiString Caption = {read=f5, write=f6};
__property int Monitor = {read=f7, write=f8};
mktMemInfo()
{
Application->CreateForm(__classid(TForm), &mktForm);
mktForm->Left = 100;
mktForm->Top = 100;
mktForm->Height = 117;
mktForm->Width = 350;
mktForm->FormStyle = fsStayOnTop;
mktForm->BorderStyle = bsToolWindow;
mktForm->Caption = "Performance graph";
mktForm->Show();
mktLabel = new TLabel(mktForm);
mktLabel->Parent = mktForm;
mktLabel->Align = alBottom;
mktLabel->Caption = "";
mktPanel = new TPanel(mktForm);
mktPanel->Parent = mktForm;
mktPanel->Align = alClient;
mktPanel->BevelInner = bvLowered;
mktPanel->BevelOuter = bvRaised;
mktPanel->BorderStyle = bsSingle;
PG = new TPerformanceGraph(mktPanel);
PG->Parent = mktPanel;
PG->Align = alClient;
PG->GridSize = 8;
PG->PenWidth = 5;
PG->StepSize = 8;
PG->Kind = pgBar;
mktTimer = new TTimer(mktForm);
mktTimer->Interval = 100;
mktTimer->OnTimer = mktTimerOn;
mktTimer->Enabled = true;
Cpu = new CCpuUsage();
}
~mktMemInfo()
{
delete mktTimer;
delete PG;
delete mktLabel;
delete mktPanel;
delete mktForm;
delete Cpu;
}
};
//---------------------------------------------------------------------------
#endif
