Ok, this is probably exploiting the very bug that we've been discussing here, but this code seems to work. You need to use the "id" parameter. It seems that if you do AddNotifyIcon() with the same "id" that you used before, it clears the old icon. So you can "effectively" change the icon by having the old one zapped into a black hole (I don't understand where it goes!).
I'm using info1.ico and info2.ico from
The zipfile here, which gives me a yellow and blue "i" - nice!
# Test Icons from http://www.royaltyfreeart.com/favicons.html
use Win32::GUI;
use strict;
my $okIcon = new Win32::GUI::Icon("info1.ico");
my $badIcon = new Win32::GUI::Icon("info2.ico");
my $lastState = 1; # start off ok
my $iconCounter = 1; # maintain an icon count
my $main = Win32::GUI::Window->new();
DoIcon($okIcon, $iconCounter); # set the initial icon
while(1){
if (int rand 2) # Yeah, This is how I do system monitoring!
{
unless ($lastState)
{
# Everything's ok now - it wasn't last time round
changeIcon($okIcon);
$lastState = 1;
}
} else {
if ($lastState)
{
# Something's gone down - everything was ok last check
changeIcon($badIcon);
$lastState = 0;
}
}
sleep(5);
}
sub DoIcon
{
my ($icon, $id) = @_;
$main->AddNotifyIcon(
-name => "Tray",
-tip => $id,
-icon => $icon,
-id => $id,
);
}
sub changeIcon
{
my $icon = shift;
DoIcon($icon, $iconCounter); # Clear the old Icon
DoIcon($icon, ++$iconCounter); # Set the new one and incriment coun
+ter
}
Let me know if it works - it might just be a funny bug on my machine. FYI. Win32::GUI version is 0.0.434, I'm running ActivePerl build 629 on Win2k.
Simon Flack ($code or die)
$,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
=~y'_"' ';eval"die";print $_,lc substr$@,0,3;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.