By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,890 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,890 IT Pros & Developers. It's quick & easy.

Trouble with Menu event and TrackPopupMenuEx()

P: n/a
Hi everyone. Hope you can help me out on this one.

I'm developing a Component which has a property ContextMenu. This component,
when placed on a form with a working ContextMenu (events assigned to
elements and proven to work with labels) displays an icon in the
notification area by calling ShellNotifyIcon() (don't want to use NotifyIcon
class). The form's ContextMenu is assigned to the property ContextMenu of
the Component. I'm able to receive every event (mouse moves, mouse clicks)
from the tray icon using a NativeWindow inside the component (let's call it
Window), and when the user right clicks the icon, I display the menu using
the following code:

<snippet>
//Make sure the menu hides when I click anywhere else
SetForegroundWindow(
new HandleRef(this.Window, this.Window.Handle));
//Show menu
TrackPopupMenuEx(
new HandleRef(this.ContextMenu, this.ContextMenu.Handle),
0x40,
System.Windows.Forms.Cursor.Position.X,
System.Windows.Forms.Cursor.Position.Y,
new HandleRef(this.Window, this.Window.Handle),
null);
//Get focus so the menu won't reload if clicked again.
PostMessage(
new HandleRef(this.Window, this.Window.Handle), 0, 0, 0);
</snippet>

The menu gets displayed correctly in the right position, but when a menu
item is clicked it just closes and nothing happens. It should execute the
code associated to that menu item like it does when it is displayed from a
label in the same form that has my Component. What is going on? I'm pretty
sure that NotifyIcon does the same thing to display its ContextMenu.

Any ideas?

thanks
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The menu gets displayed correctly in the right position, but when a menu
item is clicked it just closes and nothing happens. It should execute the
code associated to that menu item like it does when it is displayed from a
label in the same form that has my Component. What is going on?


When the regular NotifyIcon recieves a WM_COMMAND message it
dispatches it to the right object using the internal class
System.Windows.Forms.Command. Since the class is non-public, you can't
easily do the same thing.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.