473,626 Members | 3,675 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 7409
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_RBU TTONUP) {

// Make first menu item the default (bold font)
::SetMenuDefaul tItem(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
// SetForegroundWi ndow. To find out more, search for Q135788 in MSDN.
//
CPoint mouse;
GetCursorPos(&m ouse);
::SetForeground Window(m_nid.hW nd);
::TrackPopupMen u(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_cas t<System::Windo ws::Forms::Cont rol
*>(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 ContextMenuStri p
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\Dou bleClickSpeed
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_RIG HTDOWN and
MOUSEEVENTF_RIG HTUP and the cm strip displays and behaves as expected.

To simulate the lack of a DefaultItem feature in ContectMenuStri p, 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 ContextMenuStri p_ClickDefault( ByVal cm As
ContextMenuStri p)
Dim I As Integer

For I = 0 To cm.Items.Count - 1
If cm.Items(I).Fon t.Bold Then
cm.Items(I).Per formClick()
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 default. When the default MenuItem is clicked, there is code to no longer show the NotifyIcon. What I feel should happen is when I double-click the NotifyIcon in the system tray, it should perform the default menu item's Click event.
0
3323
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 want it to show the ContextMenu on a left click. This seems to be harder than it should be. I've assigned a click event to the NotifyIcon which it registers, but when I try to use: NotifyIcon1.ContextMenu.Show(Forms.Control control ,...
3
2101
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 steps). 1. Create a new Windows Forms C# solution (I called mine DBChanger). 2. Replace Form1.cs code with this: -------------------- using System;
3
10982
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 like it to display based on the relative position of the tray icon or mouse pointer if possible (whichever method works). Any help would be much appreciated. - Glen
12
18312
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 need to display the menu, I would contextMenu.Show(buttonCtrl, new Point(0)). But I can't do this for a notifyIcon because notifyIcons aren't controls. How can I display a contextMenu where the cursor is by command only? -mdb
0
2011
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 does appears correctly in the system tray while the service is running but the context menu does not pop up when the icon is right clicked. Nor does the click event fire when the icon is clicked. Any suggestions?
4
2107
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 click event. I have tried unsuccessfully using AddHandler: AddHandler nIcon.Click AddressOf nIcon_Click Private Sub nIcon_Click(ByVal sender As Object, ByVal e As EventArgs) MsgBox("Click") End Sub
0
1430
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 when i run the program when i right-click the notifyicon the first time nothing happens, but the menu shows up the second time i click it. it only seems to display the menu every-other click. makes no sense to me. I have no idea why, any help...
8
8477
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 I also want the user to be able to single left click on the icon itself to do some other functionality. Here's the problem - the single click on the menu first fires the notifyicon1_click() routine and then the menuitem1_click() routine. How do I...
0
8265
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
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 we have to send another system
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.