public struct NOTIFYICONDATA
{
public uint Size;
public IntPtr HWnd;
public uint ID;
public uint Flags;
public uint CallbackMessage;
public IntPtr HIcon;
}
[Flags]
uint NIF_MESSAGE = 0x01;
uint NIF_ICON = 0x02;
Do you know one? Please contribute it!
None.
Please add some!
uint WM_COMMAND = 0x0111;
uint WM_LBUTTONDOWN = 0x0201;
uint WM_USER = 0x0400;
uint WM_NOTIFY_TRAY = WM_USER + 2001;
public class MessageSink : MessageWindow
{
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_NOTIFY_TRAY:
// Check for Tap on our icon (ID 5000)
if((uint) m.LParam == WM_LBUTTONDOWN && (uint) m.WParam == 5000)
{
// Try icon clicked
// do something...
}
break;
default:
base.WndProc(ref m);
break;
}
}
public voi ShowIconOnTray()
{
// Obtains the app icon (the resource number is fixed for all apps)
IntPtr hIcon = LoadIcon(GetModule(null), "#32512");
// ID for the tray icon (values from 1 to 12 are reserverd by the OS)
uint uID = 5000;
NOTIFYICONDATA notdata = new NOTIFYICONDATA();
notdata.Size = 152;
notdata.HIcon = hIcon;
notdata.HWnd = this.Hwnd;
notdata.CallbackMessage = WM_NOTIFY_TRAY;
notdata.Flags = NIF_MESSAGE | NIF_ICON;
notdata.ID = uID;
Shell_NotifyIcon(NIM_ADD, ref notdata);
}
}