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 unigui中cookies使用中文汉字的方法

Delphi 删除文件函数支持撤销删除

Delphi idftp连不上ftp服务器的解决方法

Delphi android windows ios通用获取程序版本

Delphi 遍历fdquery1所有结果

Delphi 详解 enumwindows 与 enumwindowsproc

Delphi源码简单的实现粘贴复制代码

Delphi 大小排序算法代码

Delphi 编写键盘记录器

Delphi datasnap 的连接事件顺序图

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



打赏

取消

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

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

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

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

评论

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