MZSanford has asked for the wisdom of the Perl Monks concerning the following question:

I have been working on some side projects with Win32::GUI, and have run into a bit of a problem. I used some of the tips here to sort out my problems with changing the NotifyIcon, and even getting it to disappear. I now have a really nice frontend monitor program for some of the code i have written. Now, my question ...

Has anyone ever managed to make a right-click pop-up menu for the NotifyIcon ? I checked around Google and Super Search, but have found nothing useful. I have tried creating windows using special types, but have had 0 luck.
i had a memory leak once, and it ruined my favorite shirt.

Replies are listed 'Best First'.
(Guildenstern)Re: Win32::NotifyIcon pop-up menu blues
by Guildenstern (Deacon) on Oct 19, 2001 at 18:59 UTC
    I've written several apps in Visual C++ that create right-click menus, so I know this shouldn't be an impossible task. There is a known issue with getting menus to appear that is addressed in this MSDN article.
    As far as I know, you can have the popup menu load an existing resource, which seems less likely with Win32::GUI, or have it create a menu on the fly. I'd offer some code, but I haven't tried Win32::GUI yet and my VC++ code is at home. Hopefully the MSDN article will give you a push in the right direction!

    Guildenstern
    Negaterd character class uber alles!
Re: Win32::NotifyIcon pop-up menu blues
by MZSanford (Curate) on Oct 19, 2001 at 19:14 UTC
    Almost there : That MSDN artice that was suggested made me look at the GUI.xs code for TrackPopupMenu() ... a bit of magic, and i have a blank menu ... working on the emnu, then i will post a snippet.
    i had a memory leak once, and it ruined my favorite shirt.
Re: Win32::NotifyIcon pop-up menu blues
by jplindstrom (Monsignor) on Oct 20, 2001 at 21:49 UTC
    This should do it. The main window is a global ($winTransformer), and the NotifyIcon control has the name "niTray". You need to have a window, but it doesn't have to be visible.

    my $mnuTray = Win32::GUI::MakeMenu( "tray" => "tray", " > &URL" => "mnuTrayUrl", " > > &Fix" => "mnuTrayUrlFix", " > &Format" => "mnuTrayFormat", " > > Remove formatting" => "mnuTrayFormatRemove", " > > Flow" => "mnuTrayFormatFlow", " > &RegExp" => "mnuTrayRegexp", " > > Substitute" => "mnuTrayRegexpSubst", " > -" => 0, " > E&xit" => "mnuTrayExit", ); sub ::niTray_RightClick { my ($x, $y) = Win32::GUI::GetCursorPos(); $winTransformer->TrackPopupMenu($mnuTray->{tray}, $x, $y); return(1); }

    /J

      I was so close, but i was missing the offset caused by adding the tray entry in the menu. My output was a 3 pixel wide menu with no text. I added the tray level of the menu, and POOF !. Thanks so much. For the un-imaginitive, here is the code :
      sub Tray_RightClick { print "Right Click\n"; my ($x,$y) = Win32::GUI::GetCursorPos(); my $menu = new Win32::GUI::Menu( "tray" => "tray", " > exit" => "Exit", " > foo" => {-text => "foo", -name => "NI_b", -checked + => 1 }, " > bar" => "NI_b", " > foobar" => "NI_b", ); $main->TrackPopupMenu($menu->{tray}, $x, $y); 1; }

      i had a memory leak once, and it ruined my favorite shirt.