PC Review


Reply
Thread Tools Rate Thread

NotifyIcon left click menu

 
 
SteveMac
Guest
Posts: n/a
 
      5th Oct 2006
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

 
Reply With Quote
 
 
 
 
www.fruitfruit.com
Guest
Posts: n/a
 
      5th Oct 2006
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);

}
 
Reply With Quote
 
 
 
 
Steve McKewen
Guest
Posts: n/a
 
      5th Oct 2006
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


 
Reply With Quote
 
rvalstar@hotmail.com
Guest
Posts: n/a
 
      17th Oct 2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel left click produces right click menu Shoesuntied Microsoft Excel Discussion 4 18th Aug 2006 06:17 PM
the keyboard key that holds down right-click. was "accessibility and rite-click to left-click robertssubscriptions@hotmail.com Windows XP Accessibility 4 25th Feb 2006 11:19 PM
Display menu on notifyIcon with left mouse click? mdb Microsoft C# .NET 15 11th May 2005 03:31 PM
OpenNETCF NotifyIcon.Click event doesn't fire =?Utf-8?B?UmljaCBXaWxsaWFtcw==?= Microsoft Dot NET Compact Framework 0 30th Mar 2005 03:11 PM
NOTHING with Left Click Menu with right Click RoseW Windows XP Customization 2 12th Feb 2004 04:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:07 PM.