in reply to How do you toggle the system tray icon using Win32::Gui?

Awhile back Jason Bingham wrote (on the win32-gui-users list):

Don't know how supported it is but this is what I had to do is call Win32::GUI::NotifyIcon::Modify directly (it is located in the GUI.xs file for those with the source). Example works off the click on the tray icon.

Don't forget to get the -id bit the same across all calls.... Other problem I came across was the limit of 63 chars for the -tip windows doesn't like it and the good doctor will come and visit if you make it too long.

- snipped example -

Win32::GUI::NotifyIcon::Modify( $win, -id => 1, -icon => $icoDis, -tip => "Not Recording",

I would imagine this is the most "correct" way of changing the icon.

Also, you can't sleep() within a Win32::GUI program, that will freeze the UI for the user.

What you do is call Win32::GUI::Dialog(), then wait for some event to happen. There is a timer control. Return -1 from an event handler to exit the main event loop.

/J

Replies are listed 'Best First'.
Re^2: How do you toggle the system tray icon using Win32::Gui?
by sblanton (Sexton) on May 06, 2009 at 19:48 UTC
    Yeah, OK, this is old, but if I found it someone else may also. Now it's a wiki.

    In current form (ActiveState 5.8.8), the 'Win32::GUI::NotifyIcon::Modify' method is gone and so is the '-id' option. Use of the former will fail and use of the latter will produce a warning.

    'ModifyIcon' has been replaced by a 'Change' method. So to do smooth animation - like what was being attempted here, you do something like:

    our $ni; $ni = $win->AddNotifyIcon ( -icon => $ico[0], -tip => "Look both ways before crossing the street", );

    Then in the timer:

    $ni->Change( -icon => $ico[$index] );

    Sean