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 );
        }
    }
}

解决方案 »

  1.   

    Under NT/2000, PostMessage(process_hWnd, WM_SYSCOMMAND, SC_CLOSE, 0)
      

  2.   

    and you should passed hwnd to GetProccessThreadID()(****not GetWindowThreadProcessId****), and then opened the process handle for termination
      

  3.   

    Thanks Kingzai,My OS is 2000. I have tried PostMessage(process_hWnd, WM_SYSCOMMAND, SC_CLOSE, 0), but it didn't work. Is process_hWnd same with hWnd (= (HWND)FindWindow())?I didn't find GetProccessThreadID() in MSDN.
      

  4.   

    i don't know whether your hwnd is correct,you can check it by using spy++.i have an example that using hook,you can consult it.maybe help you
    http://expert.csdn.net/Expert/topic/1435/1435607.xml?temp=.7602198