Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Win32::GUI - how to catch WM_CLOSE sent from other process?

by Anonymous Monk
on May 29, 2007 at 18:57 UTC ( [id://618032]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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!

Replies are listed 'Best First'.
Re: Win32::GUI - how to catch WM_CLOSE sent from other process?
by Anonymous Monk on May 30, 2007 at 06:22 UTC
    I invented a workaround.
    I create another hidden window, attach timer to it, and in timer check $main->Text - if it's empty string or undef, then window has been closed from other process.

    Thanks for your attention!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://618032]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found