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

  1. taximania

    taximania Well-Known Member Licensed User

    Credit to AGraham for his Notification and Icon code.
    Also to DZT for the link to the NotifyIcon code.

    This lib allows you to toggle the notifyIcon Icon in the system tray.

    I'll post the class.cs files tomorrow because there's still some
    work to be done on this one !

    This works on my WM6 device un-compiled, BUT, throws wobblies when
    I try to compile it on the desktop 'for' the device.

    Instead of the notification bubble in the example, I've got it to turn my
    autoanswer and BlueTooth on/off. It works fine, as long as you don't try to
    run another b4ppc program (device, code).

    @Erel, why do I need to add a desktop reference to a lib to compile for the device, especially when the lib is designed for the device ?
    The desktop doesn't like my lib. Won't compile optimized.
    Does compile non-optimized, without a reference, but doesn't work on the device.

    Attached Files:

    Last edited: Feb 13, 2009
  2. Erel

    Erel Administrator Staff Member Licensed User

    The desktop compiler can't (always) read the device libraries. Therefore you need to supply a "dummy" library which will have methods (and namespace) with the same signature.
    It will also help other developers write code with the desktop IDE.
  3. taximania

    taximania Well-Known Member Licensed User

    I've tried to comment out the lines of code that I think the 'dummy' desktop dll won't like but i've achieved nothing.
    Here's my un-edited class.cs code. Based on the example posted by DZT.

    I've altered the original Add and Modify methods to convert the icon to a
    handle, as used in Agrahams Icon routine. Is this the problem ?
    The dll compiles and runs on my device.

    What bit's do I need to comment out for a dummy dll so I can compile programs on the desktop using this dll ?

    This is really 'bugging' me. All my other dll's have never needed this !

    using System;
    using System.Collections;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    using System.IO;
    using Microsoft.VisualBasic;
    using Microsoft.WindowsCE.Forms;
    using System.Runtime.InteropServices;

    namespace NotifyIconNS

    public class NotifyIcon : IDisposable
    public event EventHandler Click;
    private object[] eventObject;

    public string IconText
                get { 
    return iconText; }
                set { iconText = value; }

            private String iconText;

            private WS ws;
            private int uID = 5000;

            public NotifyIcon()
                eventObject = new object[] { this, "Click" };

                ws = new WS(this);
                ws.uID = uID;

            public double DLLVersion
                get { return 1; }

            public void Add(Icon ike)
                IntPtr hIcon;
                hIcon = ike.Handle;

                TrayMessage(ws.Hwnd, NIM_ADD, (uint)uID, hIcon);

            public void Remove()

                TrayMessage(ws.Hwnd, NIM_DELETE, (uint)uID, IntPtr.Zero);

            public void Modify(Icon ike2)
                IntPtr hIcon;
                hIcon = ike2.Handle;
                TrayMessage(ws.Hwnd, NIM_MODIFY, (uint)uID, hIcon);


            private void TrayMessage(IntPtr hwnd, int dwMessage, uint uID, IntPtr hIcon)
                NOTIFYICONDATA notdata = new NOTIFYICONDATA();

                notdata.cbSize = 152;
                notdata.hIcon = hIcon;
                notdata.hWnd = hwnd;
                notdata.uCallbackMessage = WM_NOTIFY_TRAY;
                notdata.uFlags = NIF_MESSAGE | NIF_ICON;
            notdata.uID = uID;

               int ret = Shell_NotifyIcon(dwMessage, ref notdata);

            public void Dispose()
                    Click = null;
                finally { }

            internal const int WM_LBUTTONDOWN = 0x0201;
            internal const int WM_NOTIFY_TRAY = 0x0400 + 2001;

            internal const int NIM_ADD = 0x00000000;
            internal const int NIM_MODIFY = 0x00000001;
            internal const int NIM_DELETE = 0x00000002;

            const int NIF_MESSAGE = 0x00000001;
            const int NIF_ICON = 0x00000002;

            internal struct NOTIFYICONDATA
                internal int cbSize;
                internal IntPtr hWnd;
                internal uint uID;
                internal uint uFlags;
                internal uint uCallbackMessage;
                internal IntPtr hIcon;

            internal static extern int Shell_NotifyIcon(
                int dwMessage, ref NOTIFYICONDATA pnid);

            internal static extern int SetForegroundWindow(IntPtr hWnd);

            internal static extern int ShowWindow(
                IntPtr hWnd,
                int nCmdShow);

           internal static extern IntPtr GetFocus();

            internal static extern IntPtr LoadIcon(IntPtr hInst, string IconName);

            internal static extern IntPtr GetModuleHandle(String lpModuleName);

            internal class WS : Microsoft.WindowsCE.Forms.MessageWindow
                private int m_uID = 0;
               private NotifyIcon notifyIcon;

                protected internal WS(NotifyIcon notIcon)
                   notifyIcon = notIcon;

                public int uID
                        m_uID = value;


                protected override void WndProc(ref Microsoft.WindowsCE.Forms.Message msg)

                    if (msg.Msg == WM_NOTIFY_TRAY)
                        if ((int)msg.LParam == WM_LBUTTONDOWN)
                            if ((int)msg.WParam == m_uID)

                                if (notifyIcon.Click != null)
                                   notifyIcon.Click(notifyIcon.eventObject, null);
  4. agraham

    agraham Expert Licensed User

    Just about everything to leave only empty properties and methods that look the same as the ones for the device.

    I've tried to upload a changed class1 for you but I'm getting "forum quota exceeded errors" :( Looks like Erel needs to wave his magic wand again!
  5. Erel

    Erel Administrator Staff Member Licensed User

    Another 20mb to the rescue...
  6. taximania

    taximania Well-Known Member Licensed User

    Consider this thread closed.

    My example works one day, then doesn't work the day after ???
    The icon stays green !! , sometimes !!
    Thanks for the help Agraham, perhaps you can sort a work round for this.

    I admit defeat, and am done with this.
    Google thinks I'm a family member of it :)
    MSDN doesn't ;)

    Not quitting the forum, perhaps some of the 'newbies' may
    need more essential little questions answered.

    If the 'OLD TIMERS' can help, then I'm sat watching :sign0188:
  7. taximania

    taximania Well-Known Member Licensed User

    Ok, I lied, this thread isn't dead.

    Finally got my, 'Device IDE', coded programs to work as expected, (on the device).

    Yes it was a coding thing on my behalf, very confusing, but 'hey'.

    What with the forum being down, i haven't the time to post everything I wanted too. I will do it tomorrow.

    @Agraham, i've tried numerous variations for a desktop dummy lib,
    the ones that do allow compilation of source code on the desktop, still don't work on the device when the exe is copied to it.

    If you can upload the file you mentioned previously, I'll try it.
  8. agraham

    agraham Expert Licensed User

    Here you are, try this. The name of the desktop assembly doesn't matter but the namespace (I think) and class name of the object and all the public method and property signatures must be identical to those of the device library.
  9. taximania

    taximania Well-Known Member Licensed User

    As usual AGraham your spot on :) Many thanks . . .

    ? If you don't show form1 in a compiled device.exe from the desktop it fails to show the icon on the device at start-up.

    If you run the device sbp, it works fine.

    Barry is getting there very slowly !!

    But losing the plot :BangHead:

    Never did like defeat, the 'Quest Continues'

    Cheers AG ;-) I'm getting there :)
    Last edited: Feb 18, 2009
  10. agraham

    agraham Expert Licensed User

    I think I understand why. The NotifyIcon needs an associated application to send messages to. Without a main form there is no message loop for your application and so nowhere to send messages to so I suspect that in this case the icon addition is cancelled.

    That's because the device IDE (unlike the desktop) is single threaded and runs your program on the IDE main thread so the NotifyIcon sees, and uses, the message loop of the IDE main window.
  11. taximania

    taximania Well-Known Member Licensed User

    Right, here's NotiIcon.dll, NotiIconDesk.dll and Balloon.dll

    I've included the on/off .bmp and .ico images/icons
    You can play with the image filepath names but the examples use
    the on/off .bmp's on the root of the device, and the on/off .ico's in the
    application directory.

    2 .sbp example files are included.
    I'm sure you can decide where your code for the toggle of state goes.

    OnOffNotify.sbp works on the device AOK :)

    OnOffNotify2.sbp can be compiled on the desktop and seems AOK :)
    I added a timer after showing form1 and hw.ShowTodayScreen in the timer1_tick routine.

    Warning for newbies, this included me,
    Make sure timer1.Enabled=False is in timer1_tick
    Every time the balloon came up to quit the app, the timer closed the balloon,
    I had to soft reset my device :BangHead:

    :wav: Cheers Agraham

    Attached Files:

    Last edited: Feb 19, 2009
  12. Erel

    Erel Administrator Staff Member Licensed User

    I see you like those two new icons ;)
  13. taximania

    taximania Well-Known Member Licensed User

    I'm getting married in August.
    Just hope she doesn't think i'm spending to much time on here.

    Basic4ppc :wav:
  14. Erel

    Erel Administrator Staff Member Licensed User

    Mazal Tov! Congratulations!
  15. taximania

    taximania Well-Known Member Licensed User

    Many thanks Erel :)

    Here's another example .sbp
    This one just sit's in the tray and toggles the icon every 5 seconds using a timer.
    The ni_click event closes the application.

    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