Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TrackPopupMenu delay

Status
Not open for further replies.

p1ato

Programmer
Aug 18, 2008
1
US
I am trying to use the Win32::GUI module to handle popup menus with a system tray icon. The problem is that when I give the menu items callbacks to execute when clicked, the callbacks don't execute until TrackPopupMenu is called a second time. I don't understand why this is happening. Here is a simple example:

-- START CODE --
use Win32::GUI ();

my $window = Win32::GUI::Window->new();
my $menu = Win32::GUI::Menu->new(-name => "TestMenu");
$menu->{"TestMenu"}->AddMenuItem(
-item => 0,
-id => 14,
-text => "Exit",
-name => "randomName",
-onClick => sub { exit; },
);
#$window->SetForegroundWindow();
$window->TrackPopupMenu($menu->{"TestMenu"}, 20, 20);
#$window->PostMessage("Msg", 0, 0);

#$window->TrackPopupMenu(Win32::GUI::Menu->new(-name => "dummyMenu"), 20, 20);

while (1) {
sleep(1);
}
-- END CODE --

Notice that while the second TrackPopupMenu call is commented, the subroutine for the menu is not called. Uncomment the second call to $window->TrackPopupMenu(...) to see how the second call will trigger the subroutine that should have executed immediately after the first call. Adding in SetForegroundWindow/PostMessage doesn't help. If someone knows how to make the subroutine get called without a second call to TrackPopupMenu I would appreciate it. Thanks!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top