c语言做的一个任务管理器
立即下载
资源介绍:
c语言做的一个任务管理器
#include "taskmgr.h"
#include ".\procpage.h"
//-------------------------------------------------------------函数声明--------------------------------------------
BOOL InsertIntoSortedArray(CPtrArray * pArray, CProcInfo * pProc);
BOOL ResortArray(CPtrArray ** ppArray);
//-------------------------------------------------------------变量声明--------------------------------------------
SYSTEM_BASIC_INFORMATION g_BasicInfo;
DWORD g_cProcesses = 0;
//
// Table of which resource IDs in the column selection dialog
// correspond to which columns
//
int g_aDlgColIDs[] =
{
IDC_IMAGENAME,
IDC_PID,
// #ifdef _HYDRA_
IDC_USERNAME,
IDC_SESSIONID,
// #endif
IDC_CPU,
IDC_CPUTIME,
IDC_MEMUSAGE,
IDC_MEMPEAK,
IDC_MEMUSAGEDIFF,
IDC_PAGEFAULTS,
IDC_PAGEFAULTSDIFF,
IDC_COMMITCHARGE,
IDC_PAGEDPOOL,
IDC_NONPAGEDPOOL,
IDC_BASEPRIORITY,
IDC_HANDLECOUNT,
IDC_THREADCOUNT,
IDC_USEROBJECTS,
IDC_GDIOBJECTS,
IDC_READOPERCOUNT,
IDC_WRITEOPERCOUNT,
IDC_OTHEROPERCOUNT,
IDC_READXFERCOUNT,
IDC_WRITEXFERCOUNT,
IDC_OTHERXFERCOUNT
};
//
// Column Default Info
//
struct
{
INT Format;
INT Width;
} ColumnDefaults[NUM_COLUMN] =
{
{ LVCFMT_LEFT, 0x6B }, // COL_IMAGENAME
{ LVCFMT_RIGHT, 50 }, // COL_PID
//#ifdef _HYDRA_
{ LVCFMT_LEFT, 0x6B }, // COL_USERNAME
{ LVCFMT_RIGHT, 70 }, // COL_SESSIONID
//#endif
{ LVCFMT_RIGHT, 35}, // COL_CPU
{ LVCFMT_RIGHT, 70 }, // COL_CPUTIME
{ LVCFMT_RIGHT, 70 }, // COL_MEMUSAGE
{ LVCFMT_RIGHT, 100 }, // COL_MEMPEAK
{ LVCFMT_RIGHT, 70 }, // COL_MEMUSAGEDIFF
{ LVCFMT_RIGHT, 70 }, // COL_PAGEFAULTS
{ LVCFMT_RIGHT, 70 }, // COL_PAGEFAULTSDIFF
{ LVCFMT_RIGHT, 70 }, // COL_COMMITCHARGE
{ LVCFMT_RIGHT, 70 }, // COL_PAGEDPOOL
{ LVCFMT_RIGHT, 70 }, // COL_NONPAGEDPOOL
{ LVCFMT_RIGHT, 60 }, // COL_BASEPRIORITY
{ LVCFMT_RIGHT, 60 }, // COL_HANDLECOUNT
{ LVCFMT_RIGHT, 60 }, // COL_THREADCOUNT
{ LVCFMT_RIGHT, 60 }, // COL_USEROBJECTS
{ LVCFMT_RIGHT, 60 }, // COL_GDIOBJECTS
{ LVCFMT_RIGHT, 70 }, // COL_READOPERCOUNT
{ LVCFMT_RIGHT, 70 }, // COL_WRITEOPERCOUNT
{ LVCFMT_RIGHT, 70 }, // COL_OTHEROPERCOUNT
{ LVCFMT_RIGHT, 70 }, // COL_READXFERCOUNT
{ LVCFMT_RIGHT, 70 }, // COL_WRITEXFERCOUNT
{ LVCFMT_RIGHT, 70 } // COL_OTHERXFERCOUNT
};
/*++ class CProcPage::SetupColumns
Class Description:
Removes any existing columns from the process listview and
adds all of the columns listed in the g_Options.m_ActiveProcCol array.
Arguments:
Return Value:
HRESULT
Revision History:
Nov-16-95 Davepl Created
--*/
static const _aIDColNames[NUM_COLUMN] =
{
IDS_COL_IMAGENAME,
IDS_COL_PID,
// #ifdef _HYDRA_
IDS_COL_USERNAME,
IDS_COL_SESSIONID,
// #endif
IDS_COL_CPU,
IDS_COL_CPUTIME,
IDS_COL_MEMUSAGE,
IDS_COL_MEMPEAK,
IDS_COL_MEMUSAGEDIFF,
IDS_COL_PAGEFAULTS,
IDS_COL_PAGEFAULTSDIFF,
IDS_COL_COMMITCHARGE,
IDS_COL_PAGEDPOOL,
IDS_COL_NONPAGEDPOOL,
IDS_COL_BASEPRIORITY,
IDS_COL_HANDLECOUNT,
IDS_COL_THREADCOUNT,
IDS_COL_USEROBJECTS,
IDS_COL_GDIOBJECTS,
IDS_COL_READOPERCOUNT,
IDS_COL_WRITEOPERCOUNT,
IDS_COL_OTHEROPERCOUNT,
IDS_COL_READXFERCOUNT,
IDS_COL_WRITEXFERCOUNT,
IDS_COL_OTHERXFERCOUNT
};
static struct
{
size_t cbOffset;
UINT idString;
}
g_OffsetMap[] =
{
{ FIELD_OFFSET(CSysInfo, m_cHandles), IDC_TOTAL_HANDLES },
{ FIELD_OFFSET(CSysInfo, m_cThreads), IDC_TOTAL_THREADS },
{ FIELD_OFFSET(CSysInfo, m_cProcesses), IDC_TOTAL_PROCESSES },
{ FIELD_OFFSET(CSysInfo, m_dwPhysicalMemory), IDC_TOTAL_PHYSICAL },
{ FIELD_OFFSET(CSysInfo, m_dwPhysAvail), IDC_AVAIL_PHYSICAL },
{ FIELD_OFFSET(CSysInfo, m_dwFileCache), IDC_FILE_CACHE },
{ FIELD_OFFSET(CSysInfo, m_dwCommitTotal), IDC_COMMIT_TOTAL },
{ FIELD_OFFSET(CSysInfo, m_dwCommitLimit), IDC_COMMIT_LIMIT },
{ FIELD_OFFSET(CSysInfo, m_dwCommitPeak), IDC_COMMIT_PEAK },
{ FIELD_OFFSET(CSysInfo, m_dwKernelPaged), IDC_KERNEL_PAGED },
{ FIELD_OFFSET(CSysInfo, m_dwKernelNP), IDC_KERNEL_NONPAGED },
{ FIELD_OFFSET(CSysInfo, m_dwKernelTotal), IDC_KERNEL_TOTAL },
};
//---------------------------------------------------------------------------------------------------------
CProcPage::CProcPage(void)
{
m_hPage = NULL;
m_hwndTabs = NULL;
m_pProcArray = NULL;
m_pvBuffer = NULL;
m_cbBuffer = 0;
m_fPaused = FALSE;
m_pszDebugger = NULL;
OnSettingsChange();
}
CProcPage::~CProcPage(void)
{
if (m_pProcArray)
{
INT c = m_pProcArray->GetSize();
while (c)
{
delete (CProcInfo *) (m_pProcArray->GetAt(c - 1));
c--;
}
delete m_pProcArray;
}
}
//-----------------------------------------------------------全局函数-----------------------------------------------
/*++ InsertIntoSortedArray
Class Description:
Sticks a CProcInfo ptr into the ptrarray supplied at the
appropriate location based on the current sort column (which
is used by the Compare member function)
Arguments:
pArray - The CPtrArray to add to
pProc - The CProcInfo object to add to the array
Return Value:
TRUE if successful, FALSE if fails
Revision History:
Nov-20-95 Davepl Created
--*/
// REVIEW (davepl) Use binary insert here, not linear
BOOL InsertIntoSortedArray(CPtrArray * pArray, CProcInfo * pProc)
{
INT cItems = pArray->GetSize();
for (INT iIndex = 0; iIndex < cItems; iIndex++)
{
CProcInfo * pTmp = (CProcInfo *) pArray->GetAt(iIndex);
if (pProc->Compare(pTmp) < 0)
{
return pArray->InsertAt(iIndex, pProc);
}
}
return pArray->Add(pProc);
}
/*++ IsTerminalServer
Routine Description:
One time call to ValidateProductSuite to
determine if we're running terminalServer
Arguments:
< None >
Return Value:
BOOL
Revision History:
Jun-30-98 alhen revised ( no creation info supplied )
--*/
BOOL IsTerminalServer()
{
static BOOL s_bIsTerminalServer = ValidateProductSuite( );
// if the exports are not available it's just the same that terminal server
// is not properly configured and terminal services options should not be available
return( s_bIsTerminalServer && gpfnWinStationGetProcessSid != NULL && gpfnCachedGetUserFromSid != NULL );
}
/* ++ ValidateProductSuite
Routine Description:
Retrieves OSVERSIONINFO, but we're only interested
in the wSuiteMask
Arguments:
< None >
Return Value:
BOOL
Revision History:
Jul-1-98 alhen
-- */
BOOL ValidateProductSuite( )
{
OSVERSIONINFOEXW osVersionInfo;
DWORDLONG dwlConditionMask = 0;
ZeroMemory( &osVersionInfo , sizeof( OSVERSIONINFOEX ) );
osVersionInfo.dwOSVersionInfoSize = sizeof( OSVERSIONINFOEX );
osVersionInfo.wSuiteMask = VER_SUITE_TERMINAL;
VER_SET_CONDITION( dwlConditionMask, VER_SUITENAME, VER_AND );
return VerifyVersionInfo( &osVersionInfo , VER_SUITENAME , dwlConditionMask );
}
//
// Take two unsigned 64-bit values an