这是一个自制的函数,函数体如下:Class XXX: {.......... public: DWORD playerPid; ............ }BOOL CALLBACK XXX::EnumWindowsProc(HWND hwnd, LPARAM lParam) { DWORD wndPid; CString Title; // lParam = procInfo.dwProcessId; // This gets the windows handle and pid of enumerated window. GetWindowThreadProcessId(hwnd, &wndPid); // This gets the windows title text from the window, using the window handle CWnd::FromHandle( hwnd )->GetWindowText(Title); // this makes sure that the PID matches that PID we started, and window // text exists, before we kill it . I don't think this is really needed, // I included it because some apps have more than one window. if ( wndPid == (DWORD)lParam && Title.GetLength() != 0) { // Please kindly close this process ::PostMessage(hwnd, WM_CLOSE, 0, 0); return false; } else { // Keep enumerating return true; } } void XXX::killProcess() { HANDLE ps = OpenProcess( SYNCHRONIZE|PROCESS_TERMINATE, FALSE, playerPid); // This function enumerates all widows, using the EnumWindowsProc callback // function, passing the PID of the process you started earlier. EnumWindows(EnumWindowsProc, playerPid); CloseHandle(ps);}
等~`
ExitThread
TerminateProcess
都可以的
ExitProcess
ExitThread
TerminateProcess
{..........
public:
DWORD playerPid;
............
}BOOL CALLBACK XXX::EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD wndPid;
CString Title;
// lParam = procInfo.dwProcessId; // This gets the windows handle and pid of enumerated window.
GetWindowThreadProcessId(hwnd, &wndPid); // This gets the windows title text from the window, using the window handle
CWnd::FromHandle( hwnd )->GetWindowText(Title); // this makes sure that the PID matches that PID we started, and window
// text exists, before we kill it . I don't think this is really needed,
// I included it because some apps have more than one window.
if ( wndPid == (DWORD)lParam && Title.GetLength() != 0)
{
// Please kindly close this process
::PostMessage(hwnd, WM_CLOSE, 0, 0);
return false;
}
else
{
// Keep enumerating
return true;
}
}
void XXX::killProcess()
{
HANDLE ps = OpenProcess( SYNCHRONIZE|PROCESS_TERMINATE, FALSE, playerPid);
// This function enumerates all widows, using the EnumWindowsProc callback
// function, passing the PID of the process you started earlier.
EnumWindows(EnumWindowsProc, playerPid);
CloseHandle(ps);}
exit
ExitProcess
killProcess
TerminateProcess
ExitThread
都不行了,比如Dead loop,那就只好重新开机啦。呵呵。