473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Trouble with Menu event and TrackPopupMenuEx()

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
1 2750
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: chauhan | last post by:
Hi, I am new to pogramming. I have written a small program which retrieves emails from server, unless all the messages are loaded only then it displays on screen properlely. Whole thing works...
3
by: Mike Stephens | last post by:
This is very simple and for the life of me the solution escapes me. How can I align a context menu to the right button of a button? Regards, Mike
2
by: weston | last post by:
So, I'm attempting to code an expanding tree menu, based off of unordered lists containing unordered lists. I'm also trying to do it in such a way that none of the javascript has to go inline with...
3
by: TPS | last post by:
Instead of using Hyperlinks and URL / Response.QueryString() parameters to pass state around in my app, I am using LinkButtons with a corresponding command event and command arguments. This page...
5
by: Mark Ingram | last post by:
Hi, ive got a form with FormBorderStyle set to None (i am using custom regions to determine the shape of the form). But i would like to be able to display the standard system menu when the user...
3
by: rsteph | last post by:
I have a javascript drop down menu that I borrowed from a website. It utilizes a little .css to help with formatting. The menu works great, and on all 3 of the browsers I'm concerned about; but I am...
2
by: MCM | last post by:
I'm working on a plotting control. The plotting control will have a context menu with basic commands for "scaling", "zooming", etc. Is there a way that, from the parent form, I can add more...
2
by: Nathan Baker | last post by:
Hey all, I've had to dive down into unmanaged world from .NET recently to subclass the IE browser window for the purposes of adding menu items. I've gotten the items added thanks to the Win32...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.