473,500 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NotifyIcon left click menu

I am using VS2003 VC++ .NET.
I want to make a tray icon with a popup menu (like a context menu) that
pops up for a left click.
I can make the notifyicon with a context menu and that works fine, but
I really want it to show the menu for a left click, exactly as it would
for a right click.

SteveMac

Oct 5 '06 #1
3 7400
SteveMac wrote:
I am using VS2003 VC++ .NET.
I want to make a tray icon with a popup menu (like a context menu) that
pops up for a left click.
I can make the notifyicon with a context menu and that works fine, but
I really want it to show the menu for a left click, exactly as it would
for a right click.

SteveMac
If you are using unmanaged C++, then refer to the following link
http://www.microsoft.com/msj/archive/sdbea.htm#fig1

Try to use WM_RBUTTONUP instead of WMLBUTTONUP.

if (lEvent==WM_RBUTTONUP) {

// Make first menu item the default (bold font)
::SetMenuDefaultItem(pSubMenu->m_hMenu, 0, TRUE);

// Display the menu at the current mouse location. There's a "bug"
// (Microsoft calls it a feature) in Windows 95 that requires calling
// SetForegroundWindow. To find out more, search for Q135788 in MSDN.
//
CPoint mouse;
GetCursorPos(&mouse);
::SetForegroundWindow(m_nid.hWnd);
::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0,
m_nid.hWnd, NULL);

}
Oct 5 '06 #2
Thanks but I am usig managed c++

I am using a notifyIcon control, and in the click event I tried to use the
context menu show method like this

Point aPoint = System::Windows::Forms::Cursor::get_Position();
Control* aCP = (Control*) sender;
trayIcon->ContextMenu->Show(__try_cast<System::Windows::Forms::Control
*>(this->trayIcon->get_Icon()), Point(0,0));
But I can't cast the notifyIcon* to a Control* for the Show method.

TIA
SteveMac
Oct 5 '06 #3
I had some similar issues w/ VB 2005 getting left click and double
click to work as desired w/ the NotifyIcon control. Here's what I did:

First I tried to capture left click or double click and either show the
context menu or launch the default item. That worked somewhat BUT:

a) The position of the cm for a left click wasn't the same as the right
click

b) The cm wouldn't automatically hide when I clicked somewhere away
from the menu / system tray icon

c) The built-in ability to select the default item (for a double click)
went away when I converted from ContextMenu to ContextMenuStrip
controls

To solve the cm (cm strip) location and hide behavior, I use WinAPI's
SendInput to do a right mouse click "whenever" I intercept a left mouse
click on the NotifyIcon control. "Whenever" needs some explanation.
What I do on a left mouse click is:

a) Start a timer that fires HKCU\Control Panel\Mouse\DoubleClickSpeed
milliseconds in the future.

b) If I capture a doubleclick, I cancel the timer and launch the cm
strip's default (bolded) item.

c) If the timer fires, it pumps out a MOUSEEVENTF_RIGHTDOWN and
MOUSEEVENTF_RIGHTUP and the cm strip displays and behaves as expected.

To simulate the lack of a DefaultItem feature in ContectMenuStrip, I
bold an item in the cmstrip and, when a double click occurs (left or
right) on the NotifyIcon, I call the following:

Private Sub ContextMenuStrip_ClickDefault(ByVal cm As
ContextMenuStrip)
Dim I As Integer

For I = 0 To cm.Items.Count - 1
If cm.Items(I).Font.Bold Then
cm.Items(I).PerformClick()
Exit For
End If
Next I

cm.Hide()
End Sub
End Class

First bolded item wins.

I'm not much of a C++ guy. If you have any issues actualizing my
programmatic right click from a timer, I'd be happy to post that VB
code.

Ciao,

Rick Valstar
r + last name + at + gmail + dot + com

Oct 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
513
by: Rob Mayo | last post by:
OK, maybe this is my opinion, maybe these are bugs. Given the folowing: I have a NotifyIcon on my Form, a Context menu associated with the NotifyIcon, and a MenuItem on the ContextMenu set as...
0
3312
by: Mike Allen | last post by:
Hi Everyone, My problem concerns ContextMenus. It's easy enough to create one and apply it to a NotifyIcon. When it's compiled and run, it works beautifully. Right click and there you are. But I...
3
2091
by: Me | last post by:
I'm getting a NullReferenceException in Unknown Module when I follow the below steps to create a simple NotifyIcon app that creates the context menu on the fly(see a little analysis after the...
3
10967
by: Glen | last post by:
Can anyone tell me if there is a workable method to get the mouse cursor position on the screen or the NotifyIcon position? I need to display a context menu for the NotifyIcon when clicked and I'd...
12
18274
by: mdb | last post by:
My app has a notify icon in the systray. I want the left mouse click to initiate a menu, and a right-mouse click to do something else. Normally, for a button, I would listen to MouseDown and if I...
0
1998
by: Neo | last post by:
I have created a Windows Service that shows a notifyicon in the system tray. I have also created a context menu for the notifyicon and implemented the notifyicons click event. The notifyicon...
4
2093
by: nospam | last post by:
I am using VB Net 2005 and want to use the notifyicon. I do not have a form, only a class. I have no problems showing or modifying the NotifyIcon, however, I am having a problem handling the...
0
1419
by: Viper | last post by:
I added a NotifyIcon to my project and a ContextMenuStrip so that when the taskbar icon is clicked a menu shows up. I added the ContextMenuStrip to the properties menu for the notifyicon. now...
8
8467
by: starrysky | last post by:
I have a program which puts an icon in the notification area and has a menu associated with it available by right clicking on the icon. I want the menu items to be selected by single left clicks but...
0
7136
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
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7232
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
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.