hennesse has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to change the icon for a NotifyIcon? My notifyIcon starts and stops a service, and I'd like to have a slightly different icon for "running" and "stopped".

The Apache webserver's system tray icon has a green dot for running and a red dot for stopped - very nice - you can tell at a glance what state it's in.

my $ni = $main->AddNotifyIcon( -name => "NI", -icon => $niIcon, -tip => "The Electronic Brewery", );

The line below attempts to change the icon. It returns success (1), but doesn't actually do anything.

$didItWork = Win32::GUI::Change($ni->{-handle}, ( -icon => $tebIcon, +));

Thanks - Dave

Replies are listed 'Best First'.
Re: Win32::GUI Notify Icon
by kejohm (Hermit) on Oct 27, 2011 at 01:47 UTC

    Try calling Change() as a method, rather than a function, since the Win32::GUI::NotifyIcon package has its own Change() method, which is different to the one in the Win32::GUI package, eg.

    $ni->Change( -icon => $tebIcon );

      kejohm,

      Wow - that worked fine. It also worked for changing -tip

      I guess the final piece is to add a timer to query the status of the service periodically and update the icon (and tooltip) accordingly. I'll work on that.

      Win32::GUI is an incredibly powerful tool. The documentation is pretty sparse, so it's really confusing for someone (like me) who's never done any GUI programming.

      Thanks for your help! -Dave

        Maybe take a look at the win32-gui-demos.pl script which comes with Win32::GUI. It's a handy little program that allows you to view the sample scripts that also come with Win32::GUI. You can view the source of the scripts (including itself) as well as run them. These scripts should provide some good examples for using Win32::GUI and should help you on your way.

        Yes, the documentation is a bit sparse. If you know what you are looking for, you can usually find information in the Microsoft MSDN Documentation Library, but that requires knowledge of the underlying Windows functions that Win32::GUI uses. Check out the source for Win32::GUI if you are keen.

        And if you are still stuck, you can always ask for help on PerlMonks :)