use Win32::GUI; use Tk; use strict; use warnings; # Win32::GUI my $main_win32 = new Win32::GUI::DialogBox( -width => 0, -height => 0, -name => 'TrayWindow' ); my $icon_nr = 0; my @icon = (new Win32::GUI::Icon( 'test.ico' ), new Win32::GUI::Icon( 'test2.ico' )); new Win32::GUI::NotifyIcon( $main_win32, -name => "Notify", -id => 255, -icon => $icon[$icon_nr], -tip => "mails and more Auftragsmanagement", -onClick => sub { &toggle_main; }, -onRightClick => sub { &context_menu; } ); #Tk my $main = MainWindow->new; my $btn_close = $main->Button( -text => ' Beenden ', -command => sub { &clean_exit } )->pack(); my $btn_switch_icon = $main->Button( -text => ' Icon ändern ', -command => sub { &toggle_icon } )->pack(); #Minimieren- und X-Button ins Tray leiten $main->protocol( 'WM_DELETE_WINDOW' => sub { $main->withdraw; } ); $main->bind( "", sub { $main->withdraw if ($main->state eq 'iconic'); } ); MainLoop; #Rechtsklickmenü aufrufen sub context_menu { my $popup = $main->Menu( Name => 'popupMenu', -tearoff => 0 ); $popup->command( -label => 'm.a.m.A. Beenden', -command => sub { &clean_exit } ); $popup->Popup( -popover => 'cursor', -popanchor => 'nw' ); return 1; } #Hauptfenster verstecken / anzeigen sub toggle_main { if ($main->state eq 'withdrawn') { $main->deiconify; $main->raise; $main->focus; } else { $main->withdraw; } } #Icon verändern sub toggle_icon { $icon_nr = !$icon_nr; Win32::GUI::NotifyIcon::Modify( $main_win32, -id => 255, -icon => $icon[$icon_nr], -tip => ' verändertes Icon ' ); } #TrayIcon erntfernen und Beenden sub clean_exit { $main_win32->Notify->Delete( -id => 255 ); CORE::exit; }