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);
}
}
}
}
}
}
}
}
Just about everything to leave only empty properties and methods that look the same as the ones for the 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 ?
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.? 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.
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.If you run the device sbp, it works fine.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?