Hi,
I try to close the aplication using the system tray but anything I do, it
doesn't seem to work.
I put the sample app I've made in this message below.
The problem is that when I click on the tray icon, instead of closing the
app, it pops up a perl interpreter error window.
If I use just
$self->Destroy;
in the event handler for that event, the application seems to be closed, but
the system tray icon remains, and the program doesn't really close. In this
case it doesn't give any error window.
If I use
$self->Close;
and in the EVT_CLOSE event handler I also destroy the tray icon, it appear
that error window.
I've searched on the internet for this error and I found a few discussions,
but I haven't seen any solution.
Am I doing something wrong? Or there is no solution of closing a WxPerl app
using Wx::TaskBarIcon?
Thank you.
Octavian
Here is the sample code I've tried:
use strict;
use Wx;
package MyApp;
use base 'Wx::App';
sub OnInit {
my $self = shift;
my $frame = MyFrame->new();
$self->SetTopWindow($frame);
$frame->Show(1);
return 1;
}
1;
package MyFrame;
use Wx qw(:everything);
use Wx::Event qw(:everything);
use base 'Wx::Frame';
sub new {
my $class = shift;
my $self = $class->SUPER::new(undef, -1, "Test", wxDefaultPosition,
wxDefaultSize);
$self->{tbi} = Wx::TaskBarIcon->new();
$self->{tbi}->SetIcon(Wx::GetWxPerlIcon, "Test program");
EVT_CLOSE($self, \&OnClose);
EVT_TASKBAR_CLICK($self->{tbi}, sub{$self->OnTBIClick($self->{tbi})});
return $self;
}
sub OnClose {
my ($self, $event) = @_;
$self->{tbi}->Destroy;
$self->Destroy;
}
sub OnTBIClick {
my ($self, $tbi) = @_;
$self->Close;
}
1;
package main;
MyApp->new->MainLoop;