NotifyIcon with Built in ContextMenu

Discussion in 'Additional Libraries' started by taximania, Feb 25, 2009.

  1. taximania

    taximania Well-Known Member Licensed User

    Run background applications and have the TrayIcon Click Event
    show a menu of options is nearly here :sign0060:

    Well, it's actually here, I'm using it, but I'm not posting the DLL yet :)

    Before I do, has anyone else done it ?
    @Agraham, i'm gonna be sick if you have, or have done already :sign0148:

    Bed time, good night fellow coders :icon_clap:
  2. agraham

    agraham Expert Licensed User

    I've done it for the desktop in ControlsExDesktop with but not for the device where my ControlsExDevice library only offers Notifier (Popup balloon) so for once you are ahead of me :icon_clap:

    You don't have to provide your own pre-built ContextMenu. If you have a ContextMenu property you can use a ContextMenu built by FormLib. See my ControlsExDesktop demo which puts a NotifyIcon with a FormLib ContextMenu in the tray when it starts. Or better you can provide both, a prebuilt ContextMenu and a ContextMenu property to override it with a custom one.
  3. taximania

    taximania Well-Known Member Licensed User

    Here's a taster.
    Please note:
    You must use "form1", you can't use this lib on other controls.
    x,y are the Top Left coords of the menu, 'spot on' in the example .sbp

    The example has the menu option to show form2
    If you show form1, the click event still works on form1 as well is the tray icon ? (I'm working on this)

    Have a play, feedback (good or bad) is appreciated :)

    Attached Files:

  4. taximania

    taximania Well-Known Member Licensed User

    I've been pondering over your comments and after studying the FormLib.cs
    i'm beginning to understand what you mean.

    I was struggling to understand how to add a new item to my menu, now I'm getting it.
    Pass it a menu item that has already been created. Now I know why FormLib needs 2 New items for a contextmenu. Create one, and pass it on.
  5. taximania

    taximania Well-Known Member Licensed User

    Resorted back to New1("form1")

    Added SetNIMenuXY(x,y) method so the menu position can be altered from within your code. Set to 100,100 by default.

    Added the Add/Remove NIContextMenu properties, and the ContextMenu class. No more pre-built menu.

    Sub ni_Click
    End Sub
    Doesn't do anything, but the program doesn't seem to work if it isn't included.

    I'm working on the desktop dummy dll.

    Attached Files:

  6. agraham

    agraham Expert Licensed User

    That's because of this unnecessary test here.
    if (((msg.Msg == 0xbd1) && (((int) msg.LParam) == 0x201)) &&
           ((((int) msg.WParam) == this.m_uID)
    "Red"] && (this.notifyIcon.Click != null[/COLOR])))
    This test is only needed before actually calling the Click event which you are not doing. Basic4ppc only assigns to this EventHandler if there is a Click event for the object declared in the B4P code which is why you need that Sub to get it to work.
  7. taximania

    taximania Well-Known Member Licensed User

    Sorted thanks. Not updated the .dll on the forum yet.


    :) I want the ability to 'Tap' the icon, to toggle the icon shown.
    Not a problem, I can do that already.

    I also want to 'tap and hold' the icon to fire the menu event ??
    Help needed here :-(

    I've spent most of this afternoon looking for WM_XXX events but haven't
    been very successful in my attempts.

    I also want other forum members who may be newbies, to know that most of the
    code used in this dll and most of my dll's are a modified version of other
    forum users, mainly Erel, Agraham and DZT. I think i got that right :)
    Sorry if I missed someone.

    I don't want credit for their work.
  8. taximania

    taximania Well-Known Member Licensed User

    Example .sbp included.

    Single Trayicon click, toggles the Icon.

    Double Trayicon click, calls the ShowNIMenu method

    Works for me :)

    If you don't understand my logic in the .sbp file,
    I'm here to help.
    Ask me.

    I'll answer as soon as I can

    :icon_clap: I feel quite proud now :sign0060:
    I've spent by far, to many hours on this :sign0148:

    Attached Files:

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice