*/ 出自: 编程中国 http://www.bc-cn.net
*/ 作者: cince
*/ 时间: 2007-9-18 编程论坛首发
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ --------------------------------------------------------------------------------------
//COM: Microsoft Studio .
Head file:
======================
symbols.h
#define IDM_EXIT 100
#define IDM_KILL 101
======================
RESOURCE.h
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
====================================
NTENUM.h
#ifndef NTENUM_H_INCLUDED
#define NTENUM_H_INCLUDED
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <vdmdbg.h>
#include <psapi.h>
#include <string.h>
#include \"enum.h\"
//Windows NT Functions
typedef BOOL (WINAPI *ENUMPROCESSES)(
DWORD * lpidProcess, // array to receive the process identifiers
DWORD cb, // size of the array
DWORD * cbNeeded // receives the number of bytes returned
);
typedef BOOL (WINAPI *ENUMPROCESSMODULES)(
HANDLE hProcess, // handle to the process
HMODULE * lphModule, // array to receive the module handles
DWORD cb, // size of the array
LPDWORD lpcbNeeded // receives the number of bytes returned
);
typedef DWORD (WINAPI *GETMODULEFILENAME)(
HANDLE hProcess, // handle to the process
HMODULE hModule, // handle to the module
LPTSTR lpstrFileName, // array to receive filename
DWORD nSize // size of filename array.
);
typedef DWORD (WINAPI *GETMODULEBASENAME)(
HANDLE hProcess, // handle to the process
HMODULE hModule, // handle to the module
LPTSTR lpstrFileName, // array to receive base name of module
DWORD nSize // size of module name array.
);
typedef INT (WINAPI *VDMENUMTASKWOWEX)(
DWORD dwProcessId, // ID of NTVDM process
TASKENUMPROCEX fp, // address of our callback function
LPARAM lparam); // anything we want to pass to the callback function.
class NT_process_enumerator : public process_enumerator {
enum { max_num = 1024 };
HANDLE psapi;
HANDLE vdmdbg;
ENUMPROCESSES EnumProcesses;
GETMODULEFILENAME GetModuleFileName;
ENUMPROCESSMODULES EnumProcessModules;
VDMENUMTASKWOWEX VDMEnumTaskWOWEx;
GETMODULEBASENAME GetModuleBaseName;
static BOOL WINAPI show_task(DWORD dwThreadId,
WORD hMod16,
WORD hTask16,
PSZ pszModName,
PSZ FileName,
LPARAM lpUserDefined);
void show_task(char const *FileName, DWORD ProcessID) {
process_enumerator::show_task(FileName, ProcessID);
}
public:
NT_process_enumerator(display &d);
virtual bool real_show();
};
#endif
======================================
MAINWND.h
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
HWND CreateMainWnd();
======================================
ERROR.h
#include \"display.h\"
class error {
public:
virtual void show(display &str) = 0;
};
class no_library : public error {
public:
virtual void show(display &str) {
str << \"Unable to load libraries\";
}
};
class no_proc : public error {
public:
virtual void show(display &str) {
str << \"Unable to get procedure addresses\";
}
};
===========================================
ENUM.h
#ifndef ENUM_H_INCLUDED
#define ENUM_H_INCLUDED
#include \"display.h\"
class process_enumerator {
void header() {
char string[256];
wsprintf(string, \" %-50s\t%10s\", \"Executable\", \"Process ID\");
disp.heading(string);
}
protected:
display &disp;
process_enumerator(display &d) : disp(d) {}
virtual bool real_show() = 0;
void show_task(char const *FileName, DWORD ProcessID) {
char string[256];
wsprintf(string, \"%-60s\t%#10x\", FileName, ProcessID);
disp << string;
}
public:
virtual void show() {
header();
real_show();
}
};
#endif
==========================================
DISPLAY.h
#ifndef DISPLAY_H_INCLUDED
#define DISPLAY_H_INCLUDED
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
class display
{
public:
virtual void show(char const *string) = 0;
virtual void heading(char const *string) = 0;
void system_error(char const *name);
virtual void resize() {}
virtual ~display() {}
};class text_display : public display {
HANDLE str;
public:
text_display(HANDLE stream = INVALID_HANDLE_VALUE);
virtual void show(char const *string);
virtual void heading(char const *string) {
show(string);
}
};class window_display : public display {
HWND output;
HWND parent;
public:
static RECT rectDefault;
window_display(HWND p, RECT &rectangle = rectDefault);
virtual void show(char const *string);
virtual void heading(char const *string);
virtual void resize();
};
inline display &operator<<(display &d, char const *string) {
d.show(string);
return d;
}
#endif
===========================================
95ENUM.h
#ifndef WIN95_ENUM_H_INLCUDED
#define WIN95_ENUM_H_INLCUDED
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tlhelp32.h> // Toolhelp 32
#include \"enum.h\"
// Win95 functions
typedef BOOL (WINAPI *PROCESSWALK)(
HANDLE hSnapshot,
LPPROCESSENTRY32 lppe
);
typedef HANDLE (WINAPI *CREATESNAPSHOT)(
DWORD dwFlags,
DWORD th32ProcessID
);
class Win95_enumerator : public process_enumerator
{
HANDLE kernel;
HANDLE snapshot;
PROCESSENTRY32 proc;
CREATESNAPSHOT CreateToolhelp32Snapshot;
PROCESSWALK Process32First;
PROCESSWALK Process32Next;
protected:
virtual bool real_show();
public:
Win95_enumerator(display &d);
};
#endif
=============================================
[此贴子已经被作者于2007-9-18 15:22:28编辑过]