Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips > Additional Libraries
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Additional Libraries Users contributed libraries.
This sub-forum is only available to licensed users.

NotifyIconChange.dll

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-13-2009, 07:09 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 592
Awards Showcase
Beta Tester 
Total Awards: 1
Default NotifyIconChange.dll

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
File Type: zip NotifyIconChange.zip (10.6 KB, 36 views)
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk

Last edited by taximania : 02-13-2009 at 07:18 PM.
Reply With Quote
  #2 (permalink)  
Old 02-14-2009, 11:02 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

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.
Reply With Quote
  #3 (permalink)  
Old 02-14-2009, 07:27 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 592
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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 !


Code:
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()
        {
           
try
            {
                Click = 
null;
                Remove();
            }
            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;
        }

        [DllImport(
"coredll.dll")]
        internal static extern 
int Shell_NotifyIcon(
            
int dwMessage, ref NOTIFYICONDATA pnid);

        [DllImport(
"coredll.dll")]
        internal static extern 
int SetForegroundWindow(IntPtr hWnd);

        [DllImport(
"coredll.dll")]
        internal static extern 
int ShowWindow(
            IntPtr hWnd,
            
int nCmdShow);

        [DllImport(
"coredll.dll")]
       internal static extern IntPtr GetFocus();

        [DllImport(
"coredll.dll")]
        internal static extern IntPtr LoadIcon(IntPtr hInst, 
string IconName);

        [DllImport(
"coredll.dll")]
        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
            {
                set
                {
                    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);
                            }
                        }
                   }
                }
            }
        }
    }
}
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
Reply With Quote
  #4 (permalink)  
Old 02-15-2009, 09:12 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by taximania View Post
What bit's do I need to comment out for a dummy dll so I can compile programs on the desktop using this dll ?
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!
Reply With Quote
  #5 (permalink)  
Old 02-15-2009, 02:50 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Another 20mb to the rescue...
Reply With Quote
  #6 (permalink)  
Old 02-15-2009, 07:29 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 592
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
Reply With Quote
  #7 (permalink)  
Old 02-17-2009, 07:31 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 592
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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.
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
Reply With Quote
  #8 (permalink)  
Old 02-18-2009, 08:47 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

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.
Reply With Quote
  #9 (permalink)  
Old 02-18-2009, 07:04 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 592
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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

Never did like defeat, the 'Quest Continues'

Cheers AG ;-) I'm getting there :-)
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk

Last edited by taximania : 02-18-2009 at 07:25 PM.
Reply With Quote
  #10 (permalink)  
Old 02-19-2009, 10:07 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by taximania View Post
? 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.
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.

Quote:
If you run the device sbp, it works fine.
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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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


All times are GMT. The time now is 06:44 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0