Win32::Monitoring::WindowPing - Test Win32 Window for responsiveness
use Win32::Monitoring::WindowPing qw( GetActiveWindow PingWindow PingStatus GetWindowCaption GetProcessIdForWindow GetNameForProcessId WAS_ALIVE WAS_TIMEOUT WAS_NOTAWINDOW WAS_OTHERERROR ); my $HWND = GetActiveWindow(); my $pingstatus = PingWindow($HWND, $timeout_in_ms); my $caption = GetWindowCaption($HWND); my $processid = GetProcessIdForWindow($HWND); my $nameforprocid = GetNameForProcessId($processid);
The Win32::Monitoring::WindowPing module provides a function to check if a windows desktop window would be willing to respond to user input if there was any. As a bonus there is a set of companion functions included, such that you can implement a nice little window alive check program without requiring further modules.
Returns the window handle of the currently active window on the window desktop
Determine is the window with the given HWND would react to user input. Return after timeout. Status is one of the following
WAS_ALIVE - The windows reacts WAS_TIMEOUT - No reaction within the timeout period WAS_NOTAWINDOW - The given HWND does not correspond to a window WAS_OTHERERROR - Something else went wrong check LastError
Get the caption of the window. The function will climb the window hierarchy until it finds a window with a proper caption.
Find the process id connected with this window.
Get the name of the binary for the process id.
#! perl use strict; use warnings; use Win32::Monitoring::WindowPing qw(:all); use Time::HiRes qw(gettimeofday usleep); my %wl; # the watchlist my $timeout = 200; while(1){ for my $hwnd (keys %wl){ usleep(1000*25); my $r = PingWindow($hwnd, $timeout); if ($r == WAS_ALIVE){ my $duration = scalar gettimeofday() - $wl{$hwnd}{hangstart}; my $caption = GetWindowCaption($hwnd); printf "%-10s hung for %8.3f s - $caption\n", $wl{$hwnd}{process}, $duration; delete $wl{$hwnd}; } elsif ($r == WAS_NOTAWINDOW){ my $duration = scalar gettimeofday() - $wl{$hwnd}{hangstart}; printf "%-10s crash after %8.3f s\n",$wl{$hwnd}{process}, $duration; delete $wl{$hwnd}; } } my $hwnd2 = GetActiveWindow(); if ($hwnd2 and not $wl{$hwnd2}){ my $r = PingWindow($hwnd2,$timeout); if ($r == WAS_TIMEOUT){ my $id = GetProcessIdForWindow($hwnd2); $wl{$hwnd2} = { hangstart => scalar gettimeofday(), process => GetNameForProcessId($id), id => $id, }; } } usleep(1000*250); };
Webpage: <http://oss.oetiker.ch/optools/>
Copyright (c) 2008 by OETIKER+PARTNER AG. All rights reserved.
Win32::Monitoring::WindowPing is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Win32::Monitoring::WindowPing is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Win32::Monitoring::WindowPing. If not, see <http://www.gnu.org/licenses/>.
Roman Plessl, Tobias Oetiker
To install Win32::Monitoring::WindowPing, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::Monitoring::WindowPing
CPAN shell
perl -MCPAN -e shell install Win32::Monitoring::WindowPing
For more information on module installation, please visit the detailed CPAN module installation guide.