You only need a new id when creating a new icon? You don't need to keep track of it? Seems like a good case to enclose a lexical:
my $id = 1; sub Yes_Mail { $main_window->TrayIconMailNo->{-id}); $main_window->{'TrayIconMailNo'}->DESTROY(); $main_window->AddNotifyIcon ( -icon => $tray_icon_file_mail_yes, -id => $id++, -name => "TrayIconMailYes", -tip => "LupoX POP3 Notifier(TM) - YOU HAVE MAIL" );
I'm not a Win32 programmer by any means, but that's how I understand your requirements.

A couple of other things could be stronger. Build a hash of event numbers and handlers instead of a large if/else switch:

my %events = ( 512 => sub { print "mouse over icon\n" }, 513 => sub { print "left button clicked\n"; }, # et cetera ); if (exists $events{$msg}) { $events{$msg}->(); }

You can also avoid reading all of the lines in a file to see if there are new messages:

open (NEW, 'mail.tmp') or die "Cannot open mail.tmp: $!\n"; if (defined(my $line = <NEW>)) { Yes_Mail(); } close NEW;

In reply to Re: Win32::GUI Task Bar Icon Bug or bad programming? by chromatic
in thread Win32::GUI Task Bar Icon Bug or bad programming? by LupoX

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.