以下是获取进程的信息的代码,有一个选择窗口自己选择需要显示的信息
.h文件
typedef struct _tag_PDHCounterStruct {
HCOUNTER hCounter; // Handle to the counter - given to use by PDH Library
int nNextIndex; // element to get the next raw value
int nOldestIndex; // element containing the oldes raw value
int nRawCount; // number of elements containing raw values
PDH_RAW_COUNTER a_RawValue[1024]; // Ring buffer to contain raw values
} PDHCOUNTERSTRUCT, *PPDHCOUNTERSTRUCT;
// Get the current value of this counter.
for(int i=0;i<ListView2->Items->Count;i++)
{
pdhStatus = PdhGetFormattedCounterValue (MyCounter[i].hCounter,PDH_FMT_LONG,
NULL,&fmtValue);
if (pdhStatus == ERROR_SUCCESS)
{
ListView2->Items->Item[i]->SubItems->Strings[0] = FormatFloat("#,###,###,##0.",fmtValue.longValue);
}
}
/* else
{
// Print the error value.
ShowMessage("错误");;
}*/
return 0;
}
int TForm1::GetTotalCommittedMemory(int ProcessID)
{
HANDLE hProcess;
Pointer pAddr =0;
int dwTotalCommit =0;
int ret;
MEMORY_BASIC_INFORMATION mi;
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,0,ProcessID);
ret = VirtualQueryEx((char*)hProcess,(char*)pAddr,&mi,sizeof(mi));
// Set the config structure members for the new buffer
gpdhBrowseDlgConfig.szReturnPathBuffer = gszReturnPath;
gpdhBrowseDlgConfig.cchReturnPathLength = gdwReturnPathSize;
// retry the counter browse selection
return PDH_RETRY;
}
returnValue = ERROR_SUCCESS;
szCurrentPath = gszReturnPath;
// This string manipulation code is in a try/except block
// to gracefully handle any problems
// with pointer values, null termination, boundary conditions, etc.
__try {
while (TRUE) {
nLen = lstrlen(szCurrentPath);