My Perl program shows NotifyIcon in Windows tray. It has no other visible windows, but it
has a special hidden window with class name (say BLAH). Other process tells that program
to terminate by sending WM_CLOSE to all windows with class name BLAH - that process really
finds all windows and sends them WM_CLOSE, but Perl code can't catch this message and hidden window just gets closed but process stays alive.
How can I catch WM_CLOSE message sent by other process? Or is there any message I can catch (sent by other process) like WM_DESTROY?
#!/usr/bin/perl
use Win32::GUI;
use strict;
my $id = 1;
my $icon = new Win32::GUI::Icon('myico.ICO');
my $classw32 = Win32::GUI::Class->new(-name => 'BLAH');
my $main = Win32::GUI::Window->new(
-name => 'Main',
-text => 'Perl',
-width => 200,
-height => 200,
-class => $classw32,
);
$main->Enable();
my $ni = $main->AddNotifyIcon(
-name => "systray",
-id => $id,
-icon => $icon,
-tip => "my tooltip",
);
my $systray_menu = new Win32::GUI::Menu(
"SystrayMenu Functions" => "SystrayMenu",
"> Exit" => "SystrayExit",
);
Win32::GUI::Dialog();
Win32::GUI::Show($main);
sub systray_RightClick {
my($x, $y) = Win32::GUI::GetCursorPos();
$main->TrackPopupMenu($systray_menu->{SystrayMenu}, $x, $y-50);
}
sub Main_Terminate {
mylog("main_term");
Win32::GUI::NotifyIcon::Delete( $ni, -id => $id );
return -1;
}
sub Main_Close {
mylog("main_close");
Win32::GUI::NotifyIcon::Delete( $ni, -id => $id );
return -1;
}
sub systray_Terminate {
mylog("systr_term");
Win32::GUI::NotifyIcon::Delete( $ni, -id => $id );
return -1;
}
sub SystrayExit_Click
{
Main_Terminate();
};
sub mylog
{
my ($str) = @_;
open(F,">>log");
print F "logged $str\n";
close F;
}
Thank you in advance for your answers!