A recently participated project requires remote task management functions, which is "Remote Task Manager" (RTM). I compared it with the Task Manager of Windows NT and found that the standard task manager displays the status of the application (running or no response). Standard Task Manager Send (via SendMessageTimeout function) a message to the primary application window, if the function call fails or timeout - the status of the application is "no response", otherwise the status is "running".
But I have found there is a better solution. This article will be demonstrated by an example program. The idea of this method is to be implemented by calling a unapproved function in USER32.DLL. This function exists in Windows 9x and Windows NT / 2000 systems, but the names in both systems are different. The name in the Windows 9x system is: IShungthread, the name in the Windows NT / 2000 system is IShungappWindow. Here are their prototypes:
Bool ishungappwindow
HWND HWND, // Main Application Window Handle
);
with
Bool ishungthread (
DWORD DWTHREADID, // Main Application Window Thread ID
);
Unfortunately, Microsoft did not provide the output of these two functions in user32.lib. That is, these two functions are undisclosed, if they are used to use them in the program, they must be dynamically loaded through the getProcAddress and getModuleHandle functions:
Typedef Bool (WinApi * ProcishungAppWindow) (HWND);
Typedef Bool (WinApi * Procishungthread (DWORD);
Procishungappwindow iShungappwindow;
PROCINGTHREAD ISHUNGTHREAD;
HModule huser32 = getModuleHandle ("User32");
IShungappwindow = (procishungappwindow)
GetProcaddress (Huser32, "IshungAppWindow);
Ishungthread = (procishungthread)
GetProcaddress (huser32, "ishungthread");
//
// 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
//Mailto: ashot@aha.ru,
http://www.protect-me.com,
http://www.codepile.com
#include
#include
// 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;
PROCINGTHREAD ISHUNGTHREAD;
Void main (int Argc, char * argv [])
{
/ * IF (Argc <2)
{
Printf ("usage: /nishung.exe hwnd / n");
Return;
}
* /
// hWnd hwnd;
// SSCANF (Argv [1], "% lx", & hwnd);
HWND HWND = :: FindWindow (NULL, "CLENT");
IF (hwnd == null)
{
Printf ("IncorRect Window Handle (Handle Is Null) / N");
Return;
}
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.dwosveionsInfosize = Sizeof (OsversionInfo);
IF (! getVersionex (& osver))
Return;
Bool iShung;
IF (OSVER.DWPLATFORMID & VER_PLATFORM_WIN32_NT)
IShung = ishungappwindow (hwnd);
Else
Ishung = ishungthread (GetwindowThreadProcessid (HWNDOWTHREADPROCESSID (HWND, NULL);
IF (iShung)
Printf ("Not Responding / N");
Else
Printf ("Running / N");
}