NotifyIcon with Built in ContextMenu

taximania

Well-Known Member
Licensed User
Longtime 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:
 

agraham

Expert
Licensed User
Longtime User
@Agraham, i'm gonna be sick if you have, or have done already
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.
 

taximania

Well-Known Member
Licensed User
Longtime User
Here's a taster.
Please note:
New1("form1",x,y)
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 :)
 

Attachments

  • miniMenu2.zip
    15.5 KB · Views: 32

taximania

Well-Known Member
Licensed User
Longtime User
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.


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.
 

taximania

Well-Known Member
Licensed User
Longtime 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.

B4X:
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.
 

Attachments

  • miniMenu3.zip
    15.3 KB · Views: 18

agraham

Expert
Licensed User
Longtime User
Doesn't do anything, but the program doesn't seem to work if it isn't included.
That's because of this unnecessary test here.
B4X:
   if (((msg.Msg == 0xbd1) && (((int) msg.LParam) == 0x201)) &&
       ((((int) msg.WParam) == this.m_uID)
        [COLOR="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.
 

taximania

Well-Known Member
Licensed User
Longtime User
Sorted thanks. Not updated the .dll on the forum yet.

TOTALLY OFF TOPIC !!

:) 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.
 

taximania

Well-Known Member
Licensed User
Longtime 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:
 

Attachments

  • miniMenu4.zip
    8.9 KB · Views: 42
Top