I try to close the process of ICQ by following code. But GetWindowThreadProcessId() get zero pid. If I use ::SendMessage(hWnd,WM_CLOSE,0,0). It cannot close the process of ICQ. Any idea about it?DWORD pid = 0;
HWND hWnd;
hWnd = (HWND)FindWindow(NULL,"123456789");
if (hWnd!=0) {
// ::SendMessage(hWnd,WM_CLOSE,0,0); (not works)
if (!GetWindowThreadProcessId(hWnd, &pid)) { // pid=0 returned
if (pid>0) {
HANDLE hProcess = OpenProcess( PROCESS_TERMINATE, FALSE, pid);
TerminateProcess(hProcess, (DWORD)-1);
CloseHandle( hProcess );
}
}
}
HWND hWnd;
hWnd = (HWND)FindWindow(NULL,"123456789");
if (hWnd!=0) {
// ::SendMessage(hWnd,WM_CLOSE,0,0); (not works)
if (!GetWindowThreadProcessId(hWnd, &pid)) { // pid=0 returned
if (pid>0) {
HANDLE hProcess = OpenProcess( PROCESS_TERMINATE, FALSE, pid);
TerminateProcess(hProcess, (DWORD)-1);
CloseHandle( hProcess );
}
}
}
http://expert.csdn.net/Expert/topic/1435/1435607.xml?temp=.7602198