/* How to implement a: a function that determines whether the specified process is unresponsive. The known condition is: a process ID, to find out if the process is not responding; I find some information on the network, copy the following program, but can not detect the results, run error . contact C + + Not a long time, I hope you can help me to solve this problem, thank you. If there are other methods, please give me a hint. Thank you. */ ///////////////////////////////////////////////////////////////////////////////#include < windows.h> #include <stdio.h> dword dwresult; BOOL fresponding = SendMessageTimeout (hwndinquestion, Wm_null, 0, 0, Smto_abortifhung, , &dwresult); / fresponding is TRUE if The thread be respon Ding and // FALSE if not. typedef struct tagwndinfo { dword dwProcessId; hwnd hWnd; } wndinfo, *LPWNDINFO; bool CALLBACK Yourenumproc (HWND hwnd,lparam lparam) &nbSp { dword dwProcessId; getwindowthreadprocessid (hWnd, &dwprocessid); lpwndinfo pinfo = (lpwndinfo) LParam; if (Dwprocessid == pinfo->dwprocessid) { pinfo->hwnd = hWnd; Return FALSE; } return TRUE; } hwnd getprocessmainwnd (DWORD dwprocessid) { wndinfo wi; Wi.dwprocessid = dwProcessId; wi.hwnd = NULL; enumwindows (Yourenumproc, (LPARAM) &wi); return wi.hWnd; } //If this process does not have a window, the function returns null /**/*///////////////////////////////////////////////////////////////// int Getprocessanswer (DWORD iprocessid) {hwnd hwnd = Getprocessmainwnd (IPROCESSID);//does not exist/if (NULL = = hwnd) return ( -1); typedef bool (WINAPI *procishungappwindow) (HWND); typedef bool (WINAPI *procishungthread) (DWORD); //then define Procishungappwindow m_pIsHungAppWindow; ProcishUngthread m_pishungthread; //defines a bool type to determine whether the current operating system is Windows nt/2000 above//because of different operating systems, The way to judge whether the program is running normally is not the same bool m_bisnt; BOOL bretval; //Get version information osVersionInfo osver = {0}; osver.dwosversioninfosize = sizeof (OSVERSIONINFO); GetVersionEx (&osver)) {bretval = FALSE;} if (Bretval = = True) {if (osver.dwplatformid&ver_platform_win32_nt) {m_bisnt = true;} else{m_bisnt = FALSE;} } //gets the two function pointers hmodule HUser32 =: GetModuleHandle ("user32"); if (!huser32) {bretval = FALSE;} if (Bretval = = TRUE) {M_pishungappwindow = (Procishungappwindow) GetProcAddress (HUser32, "Ishungappwindow" ); m_pishungthread = (Procishungthread) GetProcAddress (HUser32, "Ishungthread"); if (!m_pishungappwindow &&!m_pishungthread) {bretval = FALSE;} } //then determines whether the window is functioning normally or is not responding//code as follows if (m_bisnt = = TRUE) { bool Bishung = M_pishungappwindow (hwnd); (Bishung) {return (-2);//No response}else{return (0);//running }} else{bool BIsHung =m_pishungthread (GetWindowThreadProcessId (hwnd,null)), if (Bishung) {return (-2);//No response}else{return (0);//Running }} } ////////////////////////////////////////////////////////////////////////// int Main () { //int isum = Int (Getprocessmainwnd (3616)),//3616 is process id//printf ("%d", isum); int isum = Getprocessanswer (3616/* input process id*/);p rintf ("%d", isum); return (0);}
How to implement a function that determines whether a specified process has a response or not. (GO)