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 中string字符串转换byte[]字节数组

Delphi xe5实现datetimetounix/unixtodatetime的一点小改进

Delphi 隐藏桌面图标和任务栏

Delphi中实现变长函数笔记

Delphi 获取listbox1的行值

Delphi xe7使用本身的md5单元进行字符串加密

Delphi 对话框单元

Delphi 获取文件夹时间

Delphi 获取系统进程列表和进程所在路径

Delphi 通过读取注册表信息获取桌面路径

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



打赏

取消

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

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

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

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

评论

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