Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
process.c File Reference
#include "process.h"
#include "extern.h"
#include "extra.h"
#include "dialogs.h"
#include <tlhelp32.h>
#include <winperf.h>

Go to the source code of this file.

Classes

struct  _CAWOWH
struct  _kpf

Defines

#define INDEX_STR_LEN   10
#define PN_PROCESS   TEXT("Process")
#define PN_PROCESS_ID   TEXT("ID Process")
#define PN_THREAD   TEXT("Thread")
#define CW_CLOSE_ALL   0x00000001
#define CW_CLOSE_VISIBLE_ONLY   0x00000002
#define CW_CHECK_VISIBLE_ONLY   0x00000003

Typedefs

typedef PERF_DATA_BLOCK PERF_DATA
typedef PERF_DATA_BLOCK * PPERF_DATA
typedef PERF_OBJECT_TYPE PERF_OBJECT
typedef PERF_OBJECT_TYPE * PPERF_OBJECT
typedef PERF_INSTANCE_DEFINITION PERF_INSTANCE
typedef PERF_INSTANCE_DEFINITION * PPERF_INSTANCE
typedef BOOL(WINAPI * NS_ProcessWalk )(HANDLE hSnapshot, LPPROCESSENTRY32 lppe)
typedef HANDLE(WINAPI * NS_CreateSnapshot )(DWORD dwFlags, DWORD th32ProcessID)
typedef struct _CAWOWH CAWOWH
typedef struct _kpf kpf

Functions

BOOL _FindAndKillProcessNT4 (LPSTR aProcessName, BOOL aKillProcess)
BOOL KillProcess (char *aProcessName, HWND aHwndProcess, DWORD aProcessID)
DWORD GetTitleIdx (HWND hWnd, LPTSTR Title[], DWORD LastIndex, LPTSTR Name)
PPERF_OBJECT FindObject (PPERF_DATA pData, DWORD TitleIndex)
PPERF_OBJECT NextObject (PPERF_OBJECT pObject)
PPERF_OBJECT FirstObject (PPERF_DATA pData)
PPERF_INSTANCE NextInstance (PPERF_INSTANCE pInst)
PPERF_INSTANCE FirstInstance (PPERF_OBJECT pObject)
DWORD GetPerfData (HKEY hPerfKey, LPTSTR szObjectIndex, PPERF_DATA *ppData, DWORD *pDataSize)
BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM aParam)
BOOL _FindAndKillProcess (kpf *kpfRoutines, LPSTR aProcessName, BOOL aKillProcess)
BOOL FindAndKillProcess (LPSTR aProcessName, BOOL aKillProcess)
BOOL CloseAllWindowsOfWindowHandle (HWND aHwndWindow, char *aMsgWait)

Variables

TCHAR INDEX_PROCTHRD_OBJ [2 *INDEX_STR_LEN]
DWORD PX_PROCESS
DWORD PX_PROCESS_ID
DWORD PX_THREAD

Class Documentation

struct _CAWOWH

Definition at line 81 of file process.c.

Class Members
DWORD cwState
DWORD processID
struct _kpf

Definition at line 87 of file process.c.

Class Members
NS_CreateSnapshot pCreateToolhelp32Snapshot
NS_ProcessWalk pProcessWalkFirst
NS_ProcessWalk pProcessWalkNext

Define Documentation

#define CW_CHECK_VISIBLE_ONLY   0x00000003

Definition at line 53 of file process.c.

#define CW_CLOSE_ALL   0x00000001

Definition at line 51 of file process.c.

#define CW_CLOSE_VISIBLE_ONLY   0x00000002

Definition at line 52 of file process.c.

Definition at line 45 of file process.c.

#define PN_PROCESS   TEXT("Process")

Definition at line 46 of file process.c.

Definition at line 47 of file process.c.

#define PN_THREAD   TEXT("Thread")

Definition at line 48 of file process.c.


Typedef Documentation

typedef struct _CAWOWH CAWOWH
typedef struct _kpf kpf
typedef HANDLE(WINAPI * NS_CreateSnapshot)(DWORD dwFlags, DWORD th32ProcessID)

Definition at line 59 of file process.c.

typedef BOOL(WINAPI * NS_ProcessWalk)(HANDLE hSnapshot, LPPROCESSENTRY32 lppe)

Definition at line 58 of file process.c.

typedef PERF_DATA_BLOCK PERF_DATA

Definition at line 55 of file process.c.

typedef PERF_INSTANCE_DEFINITION PERF_INSTANCE

Definition at line 57 of file process.c.

typedef PERF_OBJECT_TYPE PERF_OBJECT

Definition at line 56 of file process.c.

typedef PERF_DATA_BLOCK * PPERF_DATA

Definition at line 55 of file process.c.

typedef PERF_INSTANCE_DEFINITION * PPERF_INSTANCE

Definition at line 57 of file process.c.

typedef PERF_OBJECT_TYPE * PPERF_OBJECT

Definition at line 56 of file process.c.


Function Documentation

BOOL _FindAndKillProcess ( kpf kpfRoutines,
LPSTR  aProcessName,
BOOL  aKillProcess 
)
BOOL _FindAndKillProcessNT4 ( LPSTR  aProcessName,
BOOL  aKillProcess 
)
BOOL CloseAllWindowsOfWindowHandle ( HWND  aHwndWindow,
char *  aMsgWait 
)

Definition at line 215 of file process.c.

{
  CAWOWH closeWindowInfo;
  BOOL  rv = TRUE;

  assert(aHwndWindow);
  assert(aMsgWait);
  if(*aMsgWait != '\0')
    ShowMessage(aMsgWait, TRUE);

  GetWindowThreadProcessId(aHwndWindow, &closeWindowInfo.processID);

  /* only close the visible windows */
  closeWindowInfo.cwState = CW_CLOSE_VISIBLE_ONLY;
  EnumWindows(EnumWindowsProc, (LPARAM)&closeWindowInfo);

  /* only check to make sure that the visible windows were closed */
  closeWindowInfo.cwState = CW_CHECK_VISIBLE_ONLY;
  rv = EnumWindows(EnumWindowsProc, (LPARAM)&closeWindowInfo);
  if(rv)
  {
    /* All visible windows have been closed.  Close all remaining windows now */
    closeWindowInfo.cwState = CW_CLOSE_ALL;
    EnumWindows(EnumWindowsProc, (LPARAM)&closeWindowInfo);
  }
  if(*aMsgWait != '\0')
    ShowMessage(aMsgWait, FALSE);

  return(rv);
}

Here is the call graph for this function:

BOOL CALLBACK EnumWindowsProc ( HWND  hwnd,
LPARAM  aParam 
)
BOOL FindAndKillProcess ( LPSTR  aProcessName,
BOOL  aKillProcess 
)

Definition at line 106 of file process.c.

{
  HANDLE hKernel       = NULL;
  BOOL   bDoWin95Check = TRUE;
  kpf    kpfRoutines;

  if((hKernel = GetModuleHandle("kernel32.dll")) == NULL)
    return(FALSE);

  kpfRoutines.pCreateToolhelp32Snapshot = (NS_CreateSnapshot)GetProcAddress(hKernel, "CreateToolhelp32Snapshot");
  kpfRoutines.pProcessWalkFirst         = (NS_ProcessWalk)GetProcAddress(hKernel,    "Process32First");
  kpfRoutines.pProcessWalkNext          = (NS_ProcessWalk)GetProcAddress(hKernel,    "Process32Next");

  if(kpfRoutines.pCreateToolhelp32Snapshot && kpfRoutines.pProcessWalkFirst && kpfRoutines.pProcessWalkNext)
    return(_FindAndKillProcess(&kpfRoutines, aProcessName, aKillProcess));
  else
    return(_FindAndKillProcessNT4(aProcessName, aKillProcess));
}

Here is the call graph for this function:

PPERF_OBJECT FindObject ( PPERF_DATA  pData,
DWORD  TitleIndex 
)
DWORD GetPerfData ( HKEY  hPerfKey,
LPTSTR  szObjectIndex,
PPERF_DATA ppData,
DWORD pDataSize 
)
DWORD GetTitleIdx ( HWND  hWnd,
LPTSTR  Title[],
DWORD  LastIndex,
LPTSTR  Name 
)
BOOL KillProcess ( char *  aProcessName,
HWND  aHwndProcess,
DWORD  aProcessID 
)

Variable Documentation

Definition at line 61 of file process.c.

Definition at line 62 of file process.c.

Definition at line 63 of file process.c.

Definition at line 64 of file process.c.