[align=center]怎么实现一个:判断指定进程有无响应的功能函数.
已知条件为:一个进程ID,求这个进程有无响应;用VC平台实现.
我在网络查找一些资料,copy后得出以下一个程序,但不能检测出结果,运行时会出错.接触C++不是很长时间,希望大家能帮帮我,解决这个问题,谢谢.
如果还有其它方法,请给予提示.谢谢.[/align]///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <stdio.h>
typedef   struct   tagWNDINFO   
{   
DWORD   dwProcessId;   
HWND   hWnd;   
}   WNDINFO,   *LPWNDINFO;   BOOL CALLBACK YourEnumProc(HWND hWnd,LPARAM  lParam)   
{   
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;   
}  
//如果这个进程没有窗口,函数返回NULL /** /*/
//////////////////////////////////////////////////////////////////////////
int GetProcessAnswer(DWORD iProcessid)
{
HWND hwnd = GetProcessMainWnd(iProcessid);
//不存在/
if(NULL == hwnd)return(-1);

typedef BOOL (WINAPI *PROCISHUNGAPPWINDOW)(HWND);
typedef BOOL (WINAPI *PROCISHUNGTHREAD)(DWORD);

//然后定义
PROCISHUNGAPPWINDOW    m_pIsHungAppWindow;
PROCISHUNGTHREAD    m_pIsHungThread;

//定义一个bool型,来判断当前操作系统是否是Windows NT/2000以上
// 因为不同的操作系统,判断程序是否运行正常的方式是不一样的

BOOL m_bIsNT;
BOOL bRetVal;

//获取版本信息
OSVERSIONINFO osver = {0};

osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!GetVersionEx(&osver))
{
bRetVal = FALSE;
}


if(bRetVal == TRUE)
{
if (osver.dwPlatformId&VER_PLATFORM_WIN32_NT)
{
m_bIsNT = TRUE;
}
else
{
m_bIsNT = FALSE;
}

}

//获取那两个函数指针
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;
}

}

//于是判断,窗口是否是正常运行,还是未响应
// 代码如下

if(m_bIsNT == TRUE)
{  
BOOL bIsHung = m_pIsHungAppWindow(hwnd);
if(bIsHung)
{
return(-2);//没有响应
}
else

return(0);//正在运行    
}
}   
else
{
BOOL bIsHung =m_pIsHungThread(GetWindowThreadProcessId(hwnd,NULL));
if(bIsHung)
{
return(-2);//没有响应
}
else

return(0);//正在运行    
}
}


}//////////////////////////////////////////////////////////////////////////
int main()
{

// int iSum = int(GetProcessMainWnd(3616));//3616是进程ID
// printf("%d",isum);
int isum = GetProcessAnswer(3616/*这里输入进程ID*/);
printf("%d",isum);

return(0);
}