use Win32::GUI; use Tk; use strict; use warnings; my $current_id = 1; my $is_in_tray = 0; my $unmap_trigger = 0; my $main_win32 = new Win32::GUI::DialogBox( -width => 0, -height => 0, -name => 'MainWindow' ); my $icon = new Win32::GUI::Icon( 'test.ico' ); my $main = MainWindow -> new; $main->geometry('100x100'); #$main->overrideredirect(1); $main->protocol( 'WM_DELETE_WINDOW' => [ \&minimize_to_tray ] ); $main->bind("",sub{ $unmap_trigger++; if ($unmap_trigger % 3 == 0) { $main->withdraw; &minimize_to_tray; } } ); my $btn_minimize = $main->Button( -text => 'Minimize', -command => [ \&minimize_to_tray ] ); my $btn_close = $main->Button( -text => 'Close', -command => [ \&clean_exit ] ); $btn_minimize->place( -x => 10, -y => 5 ); $btn_close->place( -x => 10, -y => 30 ); MainLoop; sub context_menu { my $popup = $main->Menu( Name => 'popupMenu', -tearoff => 0 ); $popup->command( -label => 'Beenden', -command => [ \&clean_exit ] ); $popup->Popup( -popover => 'cursor', -popanchor => 'nw' ); return 1; } sub raise_main { $is_in_tray = 0; $main->deiconify; $main->raise; $main->focus; return -1; } sub minimize_to_tray { $is_in_tray = 1; $main->withdraw; new Win32::GUI::NotifyIcon( $main_win32, -name => "Notify", -id => ++$current_id, -icon => $icon, -tip => "M.A.M.A.", -onClick => sub { &raise_main; }, -onRightClick => sub { &context_menu; } ); my $call = Win32::GUI::Dialog(); $main_win32->Notify->Delete( -id => $current_id ); } sub clean_exit { $main_win32->Notify->Delete( -id => $current_id ) if ($is_in_tray == 1); exit(0); }