delphi判断程序是否无响应


本文整理自网络,侵删。

 function IsAppRespondig9X(dwThreadId: DWORD): Boolean; 
type
TIsHungThread = function(dwThreadId: DWORD): BOOL; stdcall;
var
hUser32: THandle;
IsHungThread: TIsHungThread;
begin
Result := True;
hUser32 := GetModuleHandle('user32.dll');
if (hUser32 > 0) then
begin
@IsHungThread := GetProcAddress(hUser32, 'IsHungThread');
if Assigned(IsHungThread) then
begin
Result := not IsHungThread(dwThreadId);
end;
end;
end;

function IsAppRespondigNT(wnd: HWND): Boolean;
type
TIsHungAppWindow = function(wnd:hWnd): BOOL; stdcall;
var
hUser32: THandle;
IsHungAppWindow: TIsHungAppWindow;
begin
Result := True;
hUser32 := GetModuleHandle('user32.dll');
if (hUser32 > 0) then
begin
@IsHungAppWindow := GetProcAddress(hUser32, 'IsHungAppWindow');
if Assigned(IsHungAppWindow) then
begin
Result := not IsHungAppWindow(wnd);
end;
end;
end;

function IsAppRespondig(Wnd: HWND): Boolean;
begin
if not IsWindow(Wnd) then
begin
ShowMessage('Incorrect window handle!');
Exit;
end;
if Win32Platform = VER_PLATFORM_WIN32_NT then
Result := IsAppRespondigNT(wnd)
else
Result := IsAppRespondig9X(GetWindowThreadProcessId(Wnd,nil));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Res: DWORD;
h: HWND;
begin
h := FindWindow(nil, 'notepad');
if h > 0 then
begin
if IsAppRespondig(h) then
ShowMessage('notepad 有响应')
else
ShowMessage('notepad 无响应');
end
else
ShowMessage('未打开 notepad');
end;

相关阅读 >>

Delphi edit只允许输入数字和小数点

Delphi xe 自己编辑xe2 vcl style(皮肤/skin)

Delphi 虚拟键码对照表

Delphi 系统服务运行桌面用户指定程序

Delphi xe8 用httpclient下载文件

如何把 Delphi 自带的内存泄露写到日志

Delphi中使用ixmlhttprequest如何用post方式提交带参

Delphi中clientdataset的用法小结

Delphi四舍五入问题解决

Delphi tform类有关属性简介

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...