MFC检测程序未响应

时间:2023-01-18 23:42:13


UpdateData();
	CWnd* hwnd = FindWindow(NULL, m_szName);// m_szName 程序名称

	if (NULL != hwnd)
	{
		HINSTANCE hDll = LoadLibrary(_T("user32.dll"));
		if (NULL != hDll)
		{
			typedef BOOL(WINAPI *PROCISHUNGAPPWINDOW)(HWND); 
			PROCISHUNGAPPWINDOW IsHungAppWindow = (PROCISHUNGAPPWINDOW)GetProcAddress(hDll, "IsHungAppWindow");
			if (IsHungAppWindow(hwnd->GetSafeHwnd()))
			{
				m_szStatus = "未响应";
			}
			else
			{
				m_szStatus = "正在运行";
			}
		}
		// LoadLibrary();
		// IsHungAppWindow();
		// IsHungThread();
	}
	else
	{
		m_szStatus = _T("未检测到程序状态!");
	}
	UpdateData(FALSE);

代码调用了User32.dll中一个未公开的函数,这个函数存在于Win 9x和Win NT/2000两个操作系统之中,

Win 9x为IsHungThread;在Win NT/2000中为IsHungAppWindow。