Hello, perl-win32-gui-users,
Now i'm trying to implement popup menu that appears on mouse right
button click on tray icon. When I run the script below then
1. On each right click on tray icon I get following warnings
Use of uninitialized value in subroutine entry at D:\perl_projects\exrc1.pl
line 68.
Argument "-notifyicons" isn't numeric in subroutine entry at
D:\perl_projects\exrc1.pl line 68.
Argument "_NotifyIcon100" isn't numeric in subroutine entry at
D:\perl_projects\exrc1.pl line 68.
Argument "-notifyicons" isn't numeric in subroutine entry at
D:\perl_projects\exrc1.pl line 68.
line 68 is the line where there is TrackPopupMenu call. Popup menu
appears.
2. Popup menu onClick handlers is not called. In debugger I can see
this. If I tried use native TrackPopupMenu from user32.dll via
Win32::API then there is no warnings but handlers not called as
before.
Methink that main window don't receive messages in some way but I
can't understand why and therefore can't think out some workaround.
Thanks for any suggestions!
use strict;
use Win32::GUI;
my $trigger = 0;
my $mw = Win32::GUI::Window->new(-name => 'mw',
-size => [400, 400],
-pos => [200, 200],
-title => "FormsTest",
-onTerminate => sub{return -1;},
-onTimer => \&T1_Timer,
-onMinimize => sub{my $self = shift;
$self->Hide();
$self->Disable();},
);
my $popupMenu = Win32::GUI::Menu->new("Options" => "Options",
">ShowMe" => {-name => "ShowMe",
onClick => \&DoShowMe},
">HideMe" => {-name => "HideMe", onClick
=> \&DoHideMe},
">Exit" => {-name => "Exit", onClick =>
\&DoExit});
my $icon_no = Win32::GUI::Icon->new('no!.ico');
my $icon_yes = Win32::GUI::Icon->new('yes!.ico');
my $ni = $mw->AddNotifyIcon(-icon => $icon_yes,
-id => 100,
-onClick => sub{$mw->Enable(); $mw->Show();
$mw->Restore() if $mw->IsIconic();},
-onRightClick => \&myTrack
,);
my $t1 = Win32::GUI::Timer->new($mw, 'T1', 20000);
$mw->Disable();
Win32::GUI::Dialog;
sub T1_Timer {
if ($trigger % 2) {
$ni->Change(-icon => $icon_yes,
-id => 100);
$mw->Enable();
$mw->Show();
$mw->SetActiveWindow();
}
else {
$ni->Change(-icon => $icon_no,
-id => 100);
$mw->Hide();
$mw->Disable();
}
$trigger++;
}
sub DoShowMe {
$mw->Enable() unless $mw->IsEnabled;
$mw->Show() unless $mw->IsVisible;
$mw->Restore() if $mw->IsIconic();
$mw->BringWindowToTop;
$mw->SetActiveWindow();
return 0;
}
sub myTrack {
my ($x, $y) = Win32::GUI::GetCursorPos;
$mw->Enable;
Win32::GUI::TrackPopupMenu($mw->{-handle}, $popupMenu->{Options}, $x, $y);
#$mw->Disable;
}
sub DoHideMe {
$mw->Hide if $mw->IsVisible;
$mw->Disable if $mw->IsEnabled;
}
sub DoExit {
$mw->Enable;
$mw->PostQuitMessage;
}
--
Best regards,
Sergey mailto:[EMAIL PROTECTED]