31 static BOOL CALLBACK EnumProc(HWND hwnd, LPARAM lp){
36 virtual BOOL OnEnumProc(HWND hwnd){
38 if (m_count < m_nAlloc)
39 m_hwnds[m_count++] = hwnd;
45 virtual BOOL OnWindow(HWND hwnd) {
53 m_current = m_count = 0;
54 m_hwnds =
new HWND [nAlloc];
63 DWORD GetCount() {
return m_count; }
65 ::EnumWindows(EnumProc, (LPARAM)
this);
70 return m_hwnds && m_current < m_count ? m_hwnds[m_current++] : NULL;
80 virtual BOOL OnWindow(HWND hwnd){
81 if (GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE) {
83 GetWindowThreadProcessId(hwnd, &pidwin);
115 DWORD GetCount() {
return m_count; }
117 m_current = (DWORD)-1;
122 m_pids =
new DWORD [nalloc];
123 if (EnumProcesses(m_pids, nalloc*
sizeof(DWORD), &m_count)) {
124 m_count /=
sizeof(DWORD);
127 }
while (nalloc <= m_count);
132 return m_pids && m_current < m_count ? m_pids[m_current++] : 0;
152 m_hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
158 CloseHandle(m_hProcess);
159 delete [] m_hModules;
162 HANDLE GetProcessHandle() {
return m_hProcess; }
163 DWORD GetCount() {
return m_count; }
167 m_current = (DWORD)-1;
172 delete [] m_hModules;
173 m_hModules =
new HMODULE [nalloc];
174 if (EnumProcessModules(m_hProcess, m_hModules,
175 nalloc*
sizeof(DWORD), &m_count)) {
176 m_count /=
sizeof(HMODULE);
179 }
while (nalloc <= m_count);
184 return m_hProcess && m_current < m_count ? m_hModules[m_current++] : 0;
195 DWORD FindProcess(LPCTSTR modname, BOOL bAddExe=TRUE, BOOL bSkipCurrentProcess = TRUE)
197 DWORD dwCurrentPID = GetCurrentProcessId();
199 for (DWORD pid=itp.First(); pid; pid=itp.Next()) {
200 TCHAR name[_MAX_PATH];
202 HMODULE hModule = itm.First();
203 if (hModule && (dwCurrentPID != pid || !bSkipCurrentProcess) )
205 GetModuleBaseName(itm.GetProcessHandle(),
206 hModule, name, _MAX_PATH);
208 std::string sModName = modname;
209 if (_strcmpi(sModName.c_str(),name)==0)
212 if (bAddExe && _strcmpi(sModName.c_str(),name)==0)
219 bool FindAndKillProcess(LPCTSTR modname, BOOL bAddExe=TRUE, BOOL bSkipCurrentProcess = TRUE)
221 DWORD dwCurrentPID = GetCurrentProcessId();
223 for (DWORD pid=itp.First(); pid; pid=itp.Next()) {
224 TCHAR name[_MAX_PATH];
226 HMODULE hModule = itm.First();
227 if (hModule && (dwCurrentPID != pid || !bSkipCurrentProcess))
229 GetModuleBaseName(itm.GetProcessHandle(),
230 hModule, name, _MAX_PATH);
232 std::string sModName = modname;
233 if (_strcmpi(sModName.c_str(),name)==0)
235 if(!KillProcess(pid,
true))
241 if (bAddExe && _strcmpi(sModName.c_str(),name)==0)
243 if(!KillProcess(pid,
true))
252 BOOL KillProcess(DWORD pid, BOOL bZap){
254 for (HWND hwnd=itw.First(); hwnd; hwnd=itw.Next()) {
255 DWORD_PTR bOKToKill = FALSE;
256 SendMessageTimeout(hwnd, WM_QUERYENDSESSION, 0, 0,
257 SMTO_ABORTIFHUNG|SMTO_NOTIMEOUTIFNOTHUNG, 5000, &bOKToKill);
260 printf(
"program do not exit!");
263 PostMessage(hwnd, WM_CLOSE, 0, 0);
267 HANDLE hp=OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE,FALSE,pid);
269 if (WaitForSingleObject(hp, 5000) != WAIT_OBJECT_0) {
271 OutputDebugStringA(
"Terminate Process normally!");
272 TerminateProcess(hp,0);
274 OutputDebugStringA(
"bzap is false!");
281 OutputDebugStringA(
"wait single object return false");
283 OutputDebugStringA(
"Terminate Process!");
284 TerminateProcess(hp,0);
291 OutputDebugStringA(
"hp is null");
Definition: EnumProcess.hpp:24
Definition: EnumProcess.hpp:190
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: EnumProcess.hpp:142
Definition: EnumProcess.hpp:77
Definition: EnumProcess.hpp:100