博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
判断窗口是否挂起
阅读量:4620 次
发布时间:2019-06-09

本文共 1738 字,大约阅读时间需要 5 分钟。

// 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
// , ,

#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:\n\nishung.exe hWnd\n");
  return;
 }

 HWND hWnd;

 sscanf(argv[1],"%lx",&hWnd);

 if (!IsWindow(hWnd))

 {
  printf("Incorrect window handle\n");
  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\n");
 else
  printf("Running\n");
}

转载于:https://www.cnblogs.com/MaxWoods/archive/2006/02/16/332120.html

你可能感兴趣的文章
分布式事务解决方案(一) 2阶段提交 & 3阶段提交 & TCC
查看>>
android之网格布局和线性布局实现注册页面
查看>>
BZOJ 1014: [JSOI2008]火星人prefix( splay + hash )
查看>>
安装ejabberd2并配置MySQL为其数据库
查看>>
angular repeat
查看>>
android 图片圆角化控件
查看>>
java第三次作业
查看>>
HP Jack介绍
查看>>
敏捷软件开发(3)---COMMAND 模式 & Active Object 模式
查看>>
poj 1062 昂贵的聘礼 解题报告
查看>>
get the page name from url
查看>>
visual studio中csproj文件中的project guid改为小写 ( notepad++ 正则)
查看>>
TeeChart显示三维的图形,使用Surface
查看>>
如何使用 Idea 远程调试 Java 代码
查看>>
加密,解密
查看>>
在C#代码中应用Log4Net(一)简单使用Log4Net
查看>>
[转]如何写软件项目技术标
查看>>
每日站立会议个人博客五
查看>>
ddd
查看>>
死磕 java同步系列之AQS起篇
查看>>