?? unit1.cpp
字號:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
int nHandleNum = 0;
Pointer Address;
int X, Y, Total;
hMapFile = CreateFileMapping((HANDLE)(0xFFFFFFFF),
NULL,
PAGE_READWRITE,
0,
10000,
"S08IMappingFile");
if( hMapFile!=NULL )
pMapFile = MapViewOfFile(hMapFile,
FILE_MAP_ALL_ACCESS,
0,
0,
0);
else
ShowMessage( "內(nèi)存映射文件句柄(hMapFile)為空" );
if( pMapFile==NULL )
{
ShowMessage( "獲取的內(nèi)存映射文件指針(pMapFile)為空" );
exit(0);
}
else
{
Address = PChar(pMapFile) + 100*4;
while( *(PInteger(Address))!=0 )
{
nHandleNum++;
Address = PChar(Address) + 4;
}
if( *(PInteger(Address))==0 && nHandleNum<100 )
{
*(PInteger(Address)) = (Integer)Handle; // 當(dāng)前實(shí)例的句柄
}
else
{
ShowMessage("監(jiān)視程序?qū)嵗^100個。");
exit(0);
}
}
// 初始化Chart1對象:
Chart1->SeriesList->Series[0]->Clear();
for( X=0; X<10; X++ )
{
Address = PChar(pMapFile) + X*4;
Total = *(PInteger(Address));
Chart1->SeriesList->Series[0]->AddY(Total, IntToStr(X+1), clRed);
}
}
//---------------------------------------------------------------------------
MESSAGE void TForm1::WmUser(TMessage Msg)
{
Integer X, Total;
Pointer Address;
// 初始化Chart1對象:
Chart1->SeriesList->Series[0]->Clear();
for( X=0; X<10; X++ )
{
Address = PChar(pMapFile) + X*4;
Total = *(PInteger(Address));
Chart1->SeriesList->Series[0]->AddY(Total, IntToStr(X+1), clRed);
}
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
bool bFindHandle = false;
Pointer Address, NextAddress;
// 刪除內(nèi)存映射文件中當(dāng)前實(shí)例的句柄
Address = PChar(pMapFile) +100*4;
while( *(PInteger(Address))!=0 && !bFindHandle )
{
if( *(PInteger(Address))==(Integer)Handle )
{
bFindHandle = true;
NextAddress = PChar(Address) + 4;
while( *(PInteger(NextAddress))!=0 )
{
*(PInteger(Address)) = *(PInteger(NextAddress));
Address = NextAddress;
NextAddress = PChar(Address) + 4;
}
*(PInteger(Address)) = 0;
}
Address = PChar(Address) + 4;
}
UnmapViewOfFile(pMapFile);
CloseHandle(hMapFile);
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -