1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include "tlhelp32.h"
HANDLE CHungDlg::GetWindowHandle(const CString& szName) { return ::FindWindow(NULL, szName); }
BOOL CHungDlg::CloseApp(HANDLE handle) { DWORD nProcessID; ::GetWindowThreadProcessId((HWND)handle,&nProcessID); return CloseApp(nProcessID); }
BOOL CHungDlg::CloseApp(DWORD ProcessId) { HANDLE hProcess = NULL; hProcess = ::OpenProcess(PROCESS_TERMINATE,FALSE,ProcessId); if (!::TerminateProcess(hProcess, 0)) { DWORD derror = GetLastError(); return FALSE; } return TRUE; }
BOOL CHungDlg::GetProcessID(const CString& szName, DWORD& ProcessID) { HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if (handle == INVALID_HANDLE_VALUE) { return FALSE; } PROCESSENTRY32 processList; processList.dwSize=sizeof(PROCESSENTRY32); BOOL bResult=Process32First(handle, &processList); BOOL bReturn=FALSE; while(bResult) { CString str=processList.szExeFile; if(str==szName) { ProcessID = processList.th32ProcessID; bReturn=TRUE; break; } else { bResult=Process32Next(handle, &processList); } } ::CloseHandle(handle); return bReturn; }
|