Hello Ladies and Gentlemen,

My first steps in Win32:GUI programming have ended here:
my small script shoult display a task bar icon. When I click a mousebutton over the icon, my POP3 account should be checked. The icon should change when new mails are on the server.
Now my problem is that after destroying one icon, i create a new with "AddNotifyIcon...".
The "-id" parameter has to be different from the first icon`s id .
So when I click on the new button (when I have mails) the old button should come up. Now using "AddNotifyIcon..." the id has again to be a new one.
I could solve the problem in generating new ids in a loop but this hurts in my eyes when reading the code.

So how do I make it more elegant?

here is the code i wrote so far:
#!/usr/bin/perl -w #use strict; use Win32::GUI; use Mail::POP3Client; $main_window = new Win32::GUI::Window( -minsize => [0, 0], -maxsize => [0, 0], -minwidth => 0, -minheight => 0, -maxwidth => 0, -maxheight => 0 ); $tray_icon_file_mail_no = new Win32::GUI::Icon("roll.ico") || die "una +ble to open icon file: $!\n"; $tray_icon_file_mail_yes = new Win32::GUI::Icon("popme.ico") || die "u +nable to open icon file: $!\n"; main(); ######################## sub Check_Mail { my $pop = new Mail::POP3Client( USER => "user", PASSWORD => "sn1ffm3", HOST => "my.pop.host", AUTH_MODE => 'PASS', DEBUG => 0 ); open (TEMP, ">mail.tmp") or die "Cannot open temp file mail.tmp: $!\n" +; my $b = $pop->Count(); for (my $i = 1; $i <= $b; $i++) { foreach ( $pop->Head( $i ) ) { /^From:\s+/i and print $_, "\n" and print TEMP "$_\n"; /^Subject:\s+/i and print $_, "\n" and print TEMP "$_\n"."***\n"; } } close TEMP; $pop->Close(); } ####################### sub Yes_Mail { ##Win32::GUI::NotifyIcon::Delete($main_window, $main_window->TrayIconM +ailNo->{-id}); ##Win32::GUI::DestroyIcon($tray_icon_file_mail_no); $main_window->{'TrayIconMailNo'}->DESTROY(); $main_window->AddNotifyIcon ( -icon => $tray_icon_file_mail_yes, -id => "1", -name => "TrayIconMailYes", -tip => "LupoX POP3 Notifier(TM) - YOU HAVE MAIL" ); sub TrayIconMailYes_Click() { #Win32::GUI::NotifyIcon::Delete($main_window, $main_window->TrayIconMa +ilYes->{-id}); #Win32::GUI::DestroyIcon($tray_icon_file_mail_yes); $main_window->{'TrayIconMailYes'}->DESTROY(); main(); print "left_clicked - and mail checked.\n"; } sub TrayIconMailYes_RightClick() { $main_window->{'TrayIconMailYes'}->DESTROY(); print "right_clicked - mail yes.\n"; return(0); } Win32::GUI::Dialog(); } sub main { $main_window->AddNotifyIcon ( -icon => $tray_icon_file_mail_no, -id => "0", -name => "TrayIconMailNo", -tip => "LupoX POP3 Notifier(TM)" ); sub TrayIconMailNo_Click() { Check_Mail(); print "right_clicked - and mail checked.\n"; open (TEMP2, "<mail.tmp") or die "Cannot open mail.tmp: $!\n"; my @mailinfo = <TEMP2>; close TEMP2; my $nr = @mailinfo; if ($nr != 0) { Yes_Mail(); } } sub TrayIconMailNo_RightClick() { Check_Mail(); print "right_clicked - and mail checked.\n"; open (TEMP2, "<mail.tmp") or die "Cannot open mail.tmp: $!\n"; my @mailinfo = <TEMP2>; close TEMP2; my $nr = @mailinfo; if ($nr != 0) { Yes_Mail(); } } sub TrayIconMailNo_MouseEvent($) { my $msg = shift; #print "mouse_event: $msg\n"; # 512 mouse over icon if ($msg == 512) { print "mouse over icon\n"; } elsif ($msg == 513) { print "left button clicked\n"; } elsif ($msg == 514) { print "left button released\n"; } elsif ($msg == 515) { print "left button doubleclicked\n"; } elsif ($msg == 516) { print "right button clicked\n"; } elsif ($msg == 517) { print "right button released\n"; } elsif ($msg == 518) { print "right button doubleclicked\n"; } elsif ($msg == 519) { print "middle button clicked\n"; } elsif ($msg == 520) { print "middle button released\n"; } elsif ($msg == 521) { print "middle button doubleclicked\n"; } else { print "unknown event: $msg\n"; } # 513 left click # 514 left released # 515 left double click # 516 right click # 517 right released # 518 right double click # 519 middle click # 520 middle released # 521 middle double click } Win32::GUI::Dialog(); }

Thank you for any critics.
Sorry to all real perl masters if my question is boring for you....

Have a good time...
Georg
perlmonks@viot.de

In reply to 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.