Glenn Linderman wrote:
Robert May wrote:
Glenn Linderman wrote:
> Hi,
>
> Last time I tried to play around with NEM menus, they didn't
work, but
> that was several years ago.
>
> 1) Do they work now?
> 2) Any one have a small working sample? I didn't find one in the
demos....
I've not played extensively with the menu support. Basic NEM
(-onClick) definitely exists and works - several of the new demos
use it:
NotifyIcon.pl
standard_images.pl
win32-gui-demos (the demo launcher itself)
[snip]
Of course the documentation for Menus
doesn't have any examples at all...
I wonder if it could be helpful to add pointers in the documentation
to the demos that use a particular feature, even if it isn't the main
thrust of the demo?
I'd prefer not to reference particular demos from the docs, as that puts
onus on us to maintain the demos, and not change their implementation.
However, a patch to add an example (or two) to the menu constructor docs
would be very welcome.
And hmm. I can't find NotifyIcon.pl or standard_images.pl in the
installed version of the demos...
They are in the CVS source samples directory, though.
Was that intentional, or an oversight?
V1.04? They're in the PPM, and installed on my machine. They're
supposed to get installed - anyone else missing them?
Another comment is that none of those files include using -onClick with
TrackPopupMenu. Which I haven't yet gotten to work. Making me wonder if
it does.
listview_drag_drop.pl uses -onClick with TrackPopupMenu, although I can
see how you might have missed that. I does work, but there are some
gotchas: the usual use of track popup menu is within a right click
handler, and you might expect something like this to work:
sub HandleRClick {
my ($self, $x, $y) = @_;
my $menu = Win32::GUI::Menu->new( .... );
TrackPopupMenu($menu->{....}, $x, $y);
return 0;
}
But it doesn't. It took me a looong time to work out why. This code
results in a WM_COMMAND message being posted to the message queue when
you select an item in the menu. By the time Win32::GUI gets around to
processing the WM_COMMAND message, you callback sub has exited, $menu
has gone out of scope, and the menu and menu object have been destroyed.
As a result, when the WM_COMMAND gets processed, Win32::GUI cannot
locate the menu object, and so cannot find either the -onClick NEN
handler, nor the menu's name to call its' MENUNAME_Click() OEM handler.
You must define $menu in a wider scope.
[Additionally, the above code would leak on every execution of
HandleRClick(), due to a bug in Win32::GUI::Menu not tidying up some
internal data fully]
Regards,
Rob.