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!

In reply to Win32::GUI - how to catch WM_CLOSE sent from other process? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.