in reply to TrackPopupMenu delay

You're supposed to use TrackPopupMenu in a callback, like
sub Tray_RightClick { $win->TrackPopupMenu($menu->{Tray}, Win32::GUI::GetCursorPos()); return 1; }
traymon.pl - Easily add a System Tray icon to an exisiting program

Replies are listed 'Best First'.
Re^2: TrackPopupMenu delay
by p1ato (Initiate) on Aug 19, 2008 at 12:55 UTC
    That is what I am doing (except I am using "-onClick => $callback, -onRightClick => $callback2" in "$window->AddNotifyIcon(...);" instead of using Name_Event). The example I gave was just simplified to show the problem and nothing else. When I use TrackPopupMenu in either case, the menu callback doesn't execute until TrackPopupMenu is called a second time, as illustrated by the simplified example.
      Hello, I got this to work by creating the menu outside of the subroutine, then calling the menu inside of the subroutine. Here's what I mean: use Win32::GUI (); ... my $menu = Win32::GUI::Menu->new(-name => "TestMenu"); $menu->{"TestMenu"}->AddMenuItem( -item => 0, -id => 14, -text => "Exit", -onClick => sub { $win->Hide(); undef $win; exit(0); }, ); sub Tray_RightClick { $win->TrackPopupMenu($menu->{"TestMenu"}, Win32::GUI::GetCursorPos()); return 1; } ... Hope this helps you... ~Morpheous1129