在外部,如何判断应用程序是否有响应? 在外部,如何判断应用程序是否有响应? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以去看看蒋老大的文章http://blog.csdn.net/jiangsheng/archive/2004/12/31/235432.aspx 转贴:思路是通过调用User32.dll中一个未公开的函数来实现的。这个函数存在于Windows 9x和Windows NT/2000系统中,但在两个系统中的名字是不同的。Windows 9x系统中的名字为:IsHungThread,在Windows NT/2000系统中的名字为IsHungAppWindow。下面是它们的原型:BOOL IsHungAppWindow (HWND hWnd, // 主应用窗口句柄);和BOOL IsHungThread (DWORD dwThreadId, // 主应用窗口的线程ID); 不幸的是,微软在User32.lib中没有提供这两个函数的输出。也就是说,这两个函数是未公开函数,如果要在程序中使用它们,则必须通过GetProcAddress和GetModuleHandle函数动态加载:typedef BOOL (WINAPI *PROCISHUNGAPPWINDOW) (HWND);typedef BOOL (WINAPI *PROCISHUNGTHREAD) (DWORD);PROCISHUNGAPPWINDOW IsHungAppWindow;PROCISHUNGTHREAD IsHungThread;HMODULE hUser32 = GetModuleHandle("user32");IsHungAppWindow = (PROCISHUNGAPPWINDOW)GetProcAddress(hUser32,"IsHungAppWindow");IsHungThread = (PROCISHUNGTHREAD)GetProcAddress(hUser32,"IsHungThread");//////////////////// ishung.cpp (Windows 95/98/NT/2000)//// This example will show you how you can obtain the current status// of the application.// //// (c)1999 Ashot Oganesyan K, SmartLine, Inc// mailto:[email protected], http://www.protect-me.com, http://www.codepile.com#include <windows.h>#include <stdio.h>// User32!IsHungAppWindow (NT specific!)//// The function retrieves the status (running or not responding) of the// specified application//// BOOL IsHungAppWindow(// HWND hWnd, // handle to main app's window// );typedef BOOL (WINAPI *PROCISHUNGAPPWINDOW)(HWND);// User32!IsHungThread (95/98 specific!)//// The function retrieves the status (running or not responding) of the// specified thread//// BOOL IsHungThread(// DWORD dwThreadId, // The identifier of the main app's window thread // );typedef BOOL (WINAPI *PROCISHUNGTHREAD)(DWORD);PROCISHUNGAPPWINDOW IsHungAppWindow;PROCISHUNGTHREAD IsHungThread;void main(int argc, char* argv[]){/* if (argc<2) { printf("Usage:ishung.exe hWnd"); return; }*/// HWND hWnd;// sscanf(argv[1],"%lx",&hWnd); HWND hWnd = ::FindWindow(NULL, "CLENT"); if (hWnd == NULL) { printf("Incorrect window handle(handle is NULL)"); return; } if (!IsWindow(hWnd)) { printf("Incorrect window handle"); return; } HMODULE hUser32 = GetModuleHandle("user32"); if (!hUser32) return; IsHungAppWindow = (PROCISHUNGAPPWINDOW) GetProcAddress( hUser32, "IsHungAppWindow" ); IsHungThread = (PROCISHUNGTHREAD) GetProcAddress( hUser32, "IsHungThread" ); if (!IsHungAppWindow && !IsHungThread) return; OSVERSIONINFO osver; osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (!GetVersionEx(&osver)) return; BOOL IsHung; if (osver.dwPlatformId&VER_PLATFORM_WIN32_NT) IsHung = IsHungAppWindow(hWnd); else IsHung = IsHungThread(GetWindowThreadProcessId(hWnd,NULL)); if (IsHung) printf("Not Responding"); else printf("Running");} 呵呵,上次网上查到过一篇和楼上连接差不多的文章,Windows 任务管理器如何确定应用程序"没有响应"(hangwire发表于2001-12-26 15:46:46) 最近参加的一个项目要求实现远程任务管理功能,也就是"Remote Task Manager"(RTM)。我把它与Windows NT的任务管理器进行了比较,发现标准的任务管理器显示应用程序的状态(正在运行或者没有响应)。标准的任务管理器发送(通过SendMessageTimeout函数)一个消息到主应用窗口,如果函数调用失败或者超时--则应用程序的状态就是"没有响应",否则状态为"正在运行"。 但我发现还有一个更好的解决方法。本文将通过实例程序进行示范。这个方法的思路是通过调用User32.dll中一个未公开的函数来实现的。这个函数存在于Windows 9x和Windows NT/2000系统中,但在两个系统中的名字是不同的。Windows 9x系统中的名字为:IsHungThread,在Windows NT/2000系统中的名字为IsHungAppWindow。下面是它们的原型:BOOL IsHungAppWindow (HWND hWnd, // 主应用窗口句柄);和BOOL IsHungThread (DWORD dwThreadId, // 主应用窗口的线程ID); 不幸的是,微软在User32.lib中没有提供这两个函数的输出。也就是说,这两个函数是未公开函数,如果要在程序中使用它们,则必须通过GetProcAddress和GetModuleHandle函数动态加载:typedef BOOL (WINAPI *PROCISHUNGAPPWINDOW) (HWND);typedef BOOL (WINAPI *PROCISHUNGTHREAD) (DWORD);PROCISHUNGAPPWINDOW IsHungAppWindow;PROCISHUNGTHREAD IsHungThread;HMODULE hUser32 = GetModuleHandle("user32");IsHungAppWindow = (PROCISHUNGAPPWINDOW)GetProcAddress(hUser32,"IsHungAppWindow");IsHungThread = (PROCISHUNGTHREAD)GetProcAddress(hUser32,"IsHungThread");http://www.vckbase.com/sourcecode/system/ishung.zip这是这篇文章的示例代码你可以去下了研究研究文章的连接偶找不到了,因为偶把网页保存下来了 转帖:一程序经常无响应(从任务管理器查看),如何能用程序判断出程序无响应.转贴:SendMessageTimeout微软推荐的方法。 如何判断一个应用程序没有响应了呢?下面这是来自MSDN的方法,原理是发一个消息到窗口,如果在指定时间(本例是1000ms)内这个消息得不到处理就认为没有响应。Const SMTO_BLOCK = &H1Const SMTO_ABORTIFHUNG = &H2Const WM_NULL = &H0Const WM_CLOSE = &H10Dim lngResult As LongDim lngReturnValue As LonglngReturnValue = SendMessageTimeout(hWnd, WM_NULL, 0&, 0&, SMTO_ABORTIFHUNG And SMTO_BLOCK, 1000, lngResult)If lngReturnValue ThenMsgBox "Responding"ElseMsgBox "Not Responding","Block tester"End If 需要说明的是,这实际上是判断一个窗口是否停止响应,如果应用程序有多个窗口,就可能出现某些窗口停止响应而另一些窗口正常的情况。这是正常现象。 另外,在USER32.DLL里有个未见文档的函数IsHungAppWindow,也是用来判断窗口是否没有响应的。它的原型是BOOL IsHungAppWindow(HWND hWnd) http://support.microsoft.com/default.aspx?scid=KB;EN-US;q304990&ID=KB;EN-US;q304990&SD=MSDN http://members.chello.be/ws36637/response.html 有关单选按钮重设问题 关于MFC GridCtrl的一个问题 setsockopt( hAcceptSocket, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,的意义? fatal error C1010: unexpected end of file while looking for precompiled header d CRichEditCtrl的流输入输出问题. 应用程序类型对话框中的【Dialog based】按钮? 马家爵... 切分窗口中如何更新视图 急!关于多媒体文件格式的确认!(BMP,AVI等) C语言网络编程 自启动问题 求最佳方法
http://blog.csdn.net/jiangsheng/archive/2004/12/31/235432.aspx
思路是通过调用User32.dll中一个未公开的函数来实现的。这个函数存在于Windows 9x和Windows NT/2000系统中,但在两个系统中的名字是不同的。Windows 9x系统中的名字为:IsHungThread,在Windows NT/2000系统中的名字为IsHungAppWindow。下面是它们的原型:
BOOL IsHungAppWindow (
HWND hWnd, // 主应用窗口句柄
);
和
BOOL IsHungThread (
DWORD dwThreadId, // 主应用窗口的线程ID
);
不幸的是,微软在User32.lib中没有提供这两个函数的输出。也就是说,这两个函数是未公开函数,如果要在程序中使用它们,则必须通过GetProcAddress和GetModuleHandle函数动态加载:
typedef BOOL (WINAPI *PROCISHUNGAPPWINDOW) (HWND);
typedef BOOL (WINAPI *PROCISHUNGTHREAD) (DWORD);
PROCISHUNGAPPWINDOW IsHungAppWindow;
PROCISHUNGTHREAD IsHungThread;
HMODULE hUser32 = GetModuleHandle("user32");
IsHungAppWindow = (PROCISHUNGAPPWINDOW)
GetProcAddress(hUser32,"IsHungAppWindow");
IsHungThread = (PROCISHUNGTHREAD)
GetProcAddress(hUser32,"IsHungThread");
//////////////////
// ishung.cpp (Windows 95/98/NT/2000)
//
// This example will show you how you can obtain the current status
// of the application.
//
//
// (c)1999 Ashot Oganesyan K, SmartLine, Inc
// mailto:[email protected], http://www.protect-me.com, http://www.codepile.com
#include <windows.h>
#include <stdio.h>
// User32!IsHungAppWindow (NT specific!)
//
// The function retrieves the status (running or not responding) of the
// specified application
//
// BOOL IsHungAppWindow(
// HWND hWnd, // handle to main app's window
// );
typedef BOOL (WINAPI *PROCISHUNGAPPWINDOW)(HWND);
// User32!IsHungThread (95/98 specific!)
//
// The function retrieves the status (running or not responding) of the
// specified thread
//
// BOOL IsHungThread(
// DWORD dwThreadId, // The identifier of the main app's window thread
// );
typedef BOOL (WINAPI *PROCISHUNGTHREAD)(DWORD);
PROCISHUNGAPPWINDOW IsHungAppWindow;
PROCISHUNGTHREAD IsHungThread;
void main(int argc, char* argv[])
{
/* if (argc<2)
{
printf("Usage:ishung.exe hWnd");
return;
}
*/
// HWND hWnd;
// sscanf(argv[1],"%lx",&hWnd);
HWND hWnd = ::FindWindow(NULL, "CLENT");
if (hWnd == NULL)
{
printf("Incorrect window handle(handle is NULL)");
return;
}
if (!IsWindow(hWnd))
{
printf("Incorrect window handle");
return;
}
HMODULE hUser32 = GetModuleHandle("user32");
if (!hUser32)
return;
IsHungAppWindow = (PROCISHUNGAPPWINDOW)
GetProcAddress( hUser32,
"IsHungAppWindow" );
IsHungThread = (PROCISHUNGTHREAD) GetProcAddress( hUser32,
"IsHungThread" );
if (!IsHungAppWindow && !IsHungThread)
return;
OSVERSIONINFO osver;
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!GetVersionEx(&osver))
return;
BOOL IsHung;
if (osver.dwPlatformId&VER_PLATFORM_WIN32_NT)
IsHung = IsHungAppWindow(hWnd);
else
IsHung = IsHungThread(GetWindowThreadProcessId(hWnd,NULL));
if (IsHung)
printf("Not Responding");
else
printf("Running");
}
(hangwire发表于2001-12-26 15:46:46) 最近参加的一个项目要求实现远程任务管理功能,也就是"Remote Task Manager"(RTM)。我把它与Windows NT的任务管理器进行了比较,发现标准的任务管理器显示应用程序的状态(正在运行或者没有响应)。标准的任务管理器发送(通过SendMessageTimeout函数)一个消息到主应用窗口,如果函数调用失败或者超时--则应用程序的状态就是"没有响应",否则状态为"正在运行"。
但我发现还有一个更好的解决方法。本文将通过实例程序进行示范。这个方法的思路是通过调用User32.dll中一个未公开的函数来实现的。这个函数存在于Windows 9x和Windows NT/2000系统中,但在两个系统中的名字是不同的。Windows 9x系统中的名字为:IsHungThread,在Windows NT/2000系统中的名字为IsHungAppWindow。下面是它们的原型:
BOOL IsHungAppWindow (
HWND hWnd, // 主应用窗口句柄
);
和
BOOL IsHungThread (
DWORD dwThreadId, // 主应用窗口的线程ID
);
不幸的是,微软在User32.lib中没有提供这两个函数的输出。也就是说,这两个函数是未公开函数,如果要在程序中使用它们,则必须通过GetProcAddress和GetModuleHandle函数动态加载:typedef BOOL (WINAPI *PROCISHUNGAPPWINDOW) (HWND);
typedef BOOL (WINAPI *PROCISHUNGTHREAD) (DWORD);PROCISHUNGAPPWINDOW IsHungAppWindow;
PROCISHUNGTHREAD IsHungThread;HMODULE hUser32 = GetModuleHandle("user32");IsHungAppWindow = (PROCISHUNGAPPWINDOW)
GetProcAddress(hUser32,"IsHungAppWindow");IsHungThread = (PROCISHUNGTHREAD)
GetProcAddress(hUser32,"IsHungThread");
http://www.vckbase.com/sourcecode/system/ishung.zip这是这篇文章的示例代码
你可以去下了研究研究
文章的连接偶找不到了,因为偶把网页保存下来了
一程序经常无响应(从任务管理器查看),如何能用程序判断出程序无响应.
转贴:
SendMessageTimeout
微软推荐的方法。
如何判断一个应用程序没有响应了呢?下面这是来自MSDN的方法,原理是发一个消息到窗口,如果在指定时间(本例是1000ms)内这个消息得不到处理就认为没有响应。
Const SMTO_BLOCK = &H1
Const SMTO_ABORTIFHUNG = &H2
Const WM_NULL = &H0
Const WM_CLOSE = &H10
Dim lngResult As Long
Dim lngReturnValue As Long
lngReturnValue = SendMessageTimeout(hWnd, WM_NULL, 0&, 0&, SMTO_ABORTIFHUNG And SMTO_BLOCK, 1000, lngResult)
If lngReturnValue Then
MsgBox "Responding"
Else
MsgBox "Not Responding","Block tester"
End If
需要说明的是,这实际上是判断一个窗口是否停止响应,如果应用程序有多个窗口,就可能出现某些窗口停止响应而另一些窗口正常的情况。这是正常现象。
另外,在USER32.DLL里有个未见文档的函数IsHungAppWindow,也是用来判断窗口是否没有响应的。它的原型是
BOOL IsHungAppWindow(HWND hWnd)
scid=KB;EN-US;q304990&ID=KB;EN-US;q304990&SD=MSDN