zoukankan      html  css  js  c++  java
  • 判断程序是否无响应

    转自《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;

    这段代码将集成在应用程序的保护线程内,用于监视程序是否无响应。

  • 相关阅读:
    初试 spring web mvc
    读取网络数据缓存在本地 流程图
    servlet 过滤器实现 请求转发(跳转);跨域转发请求;tomcat 环境下。
    C# .net基于Http实现web server(web服务)
    微信公众平台开发
    Linux目录结构及作用
    MySQL事件调度器event的使用
    MySQL触发器trigger的使用
    存储过程的查、改、删
    MySQL游标的简单实践
  • 原文地址:https://www.cnblogs.com/xieyunc/p/4438263.html
Copyright © 2011-2022 走看看