NotifyIcon left click menu

S

SteveMac

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
 
W

www.fruitfruit.com

SteveMac said:
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);

}
 
S

Steve McKewen

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
 
R

rvalstar

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top