NotifyIcon left click menu

Discussion in 'Microsoft VC .NET' started by SteveMac, Oct 5, 2006.

  1. SteveMac

    SteveMac Guest

    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
     
    SteveMac, Oct 5, 2006
    #1
    1. Advertisements

  2. 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);

    }
     
    www.fruitfruit.com, Oct 5, 2006
    #2
    1. Advertisements

  3. 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
     
    Steve McKewen, Oct 5, 2006
    #3
  4. SteveMac

    Guest

    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, 2006
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shawn B.

    Rotate Left

    Shawn B., Oct 9, 2003, in forum: Microsoft VC .NET
    Replies:
    1
    Views:
    266
    Stefan Slapeta
    Oct 9, 2003
  2. Jigar Mehta
    Replies:
    3
    Views:
    219
    Jigar Mehta
    Feb 4, 2004
  3. Alex Lu
    Replies:
    1
    Views:
    303
    Nishant S
    Dec 24, 2004
  4. Guest

    equivalent of MouseButtons.Left in VC++.NET

    Guest, Feb 28, 2006, in forum: Microsoft VC .NET
    Replies:
    1
    Views:
    272
    Guest
    Feb 28, 2006
  5. 2b|!2b==?
    Replies:
    5
    Views:
    285
    Norman Diamond
    Apr 17, 2007
Loading...

Share This Page