E
Ed Courtenay
I need to be able to set the icon on a Notification Icon Balloon Tip (a
balloon tip raised from the system tray), and I've had limited success
so far.
I've extended the standard NotifyIcon component (well, read disassembled
using Lutz Roeder's fantastic tool and rebuilt); I've added a new
Structure like this:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class NOTIFYICONDATAEX
{
public int cbSize;
public IntPtr hWnd;
public int uID;
public int uFlags;
public int uCallbackMessage;
public IntPtr hIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x80)]
public string szTip;
public int dwState;
public int dwStateMask;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
public string szInfo;
public int uTimeoutOrVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x40)]
public string szInfoTitle;
public int dwInfoFlags;
public Guid guidItem;
public IntPtr hBalloonIcon;
public NOTIFYICONDATAEX()
{
cbSize = Marshal.SizeOf(typeof (NOTIFYICONDATAEX));
hIcon = IntPtr.Zero;
hBalloonIcon = IntPtr.Zero;
}
}
and I've added an extern declaration like so:
[DllImport("shell32.dll", CharSet = CharSet.Auto,
EntryPoint="Shell_NotifyIcon")]
public static extern int Shell_NotifyIconEx(int message,
NOTIFYICONDATAEX pnid);
If I use the following to invoke Shell_NotifyIcon:
NOTIFYICONDATAEX notifyicondata1 = new NOTIFYICONDATAEX();
notifyicondata1.hWnd = window.Handle;
notifyicondata1.uID = id;
notifyicondata1.uFlags = NIF_INFO | NIF_ICON;
notifyicondata1.uTimeoutOrVersion = timeout;
notifyicondata1.szInfoTitle = tipTitle;
notifyicondata1.szInfo = tipText;
notifyicondata1.dwInfoFlags = (int)ToolTipIcon.User;
notifyicondata1.hIcon = balloonIcon.Handle;
Shell_NotifyIconEx(1, notifyicondata1);
then I raise a balloon tip with a user-supplied icon. Unfortunately, it
changes the Notification Icon as well. However, according to the docs
when using Vista you can specify hBalloonIcon independently of hIcon.
However, when I try this:
NOTIFYICONDATAEX notifyicondata1 = new NOTIFYICONDATAEX();
notifyicondata1.hWnd = window.Handle;
notifyicondata1.uID = id;
notifyicondata1.uFlags = NIF_INFO | NIF_ICON;
notifyicondata1.uTimeoutOrVersion = timeout;
notifyicondata1.szInfoTitle = tipTitle;
notifyicondata1.szInfo = tipText;
notifyicondata1.dwInfoFlags = (int)ToolTipIcon.User;
notifyicondata1.hIcon = trayIcon.Handle;
notifyicondata1.hBalloonIcon = balloonIcon.Handle;
Shell_NotifyIconEx(1, notifyicondata1);
the function returns false and no balloon tip is shown. In addition,
Win32Exception states that "The operation completed successfully". Does
anyone have any ideas?
Many thanks
Ed Courtenay
balloon tip raised from the system tray), and I've had limited success
so far.
I've extended the standard NotifyIcon component (well, read disassembled
using Lutz Roeder's fantastic tool and rebuilt); I've added a new
Structure like this:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class NOTIFYICONDATAEX
{
public int cbSize;
public IntPtr hWnd;
public int uID;
public int uFlags;
public int uCallbackMessage;
public IntPtr hIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x80)]
public string szTip;
public int dwState;
public int dwStateMask;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
public string szInfo;
public int uTimeoutOrVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x40)]
public string szInfoTitle;
public int dwInfoFlags;
public Guid guidItem;
public IntPtr hBalloonIcon;
public NOTIFYICONDATAEX()
{
cbSize = Marshal.SizeOf(typeof (NOTIFYICONDATAEX));
hIcon = IntPtr.Zero;
hBalloonIcon = IntPtr.Zero;
}
}
and I've added an extern declaration like so:
[DllImport("shell32.dll", CharSet = CharSet.Auto,
EntryPoint="Shell_NotifyIcon")]
public static extern int Shell_NotifyIconEx(int message,
NOTIFYICONDATAEX pnid);
If I use the following to invoke Shell_NotifyIcon:
NOTIFYICONDATAEX notifyicondata1 = new NOTIFYICONDATAEX();
notifyicondata1.hWnd = window.Handle;
notifyicondata1.uID = id;
notifyicondata1.uFlags = NIF_INFO | NIF_ICON;
notifyicondata1.uTimeoutOrVersion = timeout;
notifyicondata1.szInfoTitle = tipTitle;
notifyicondata1.szInfo = tipText;
notifyicondata1.dwInfoFlags = (int)ToolTipIcon.User;
notifyicondata1.hIcon = balloonIcon.Handle;
Shell_NotifyIconEx(1, notifyicondata1);
then I raise a balloon tip with a user-supplied icon. Unfortunately, it
changes the Notification Icon as well. However, according to the docs
when using Vista you can specify hBalloonIcon independently of hIcon.
However, when I try this:
NOTIFYICONDATAEX notifyicondata1 = new NOTIFYICONDATAEX();
notifyicondata1.hWnd = window.Handle;
notifyicondata1.uID = id;
notifyicondata1.uFlags = NIF_INFO | NIF_ICON;
notifyicondata1.uTimeoutOrVersion = timeout;
notifyicondata1.szInfoTitle = tipTitle;
notifyicondata1.szInfo = tipText;
notifyicondata1.dwInfoFlags = (int)ToolTipIcon.User;
notifyicondata1.hIcon = trayIcon.Handle;
notifyicondata1.hBalloonIcon = balloonIcon.Handle;
Shell_NotifyIconEx(1, notifyicondata1);
the function returns false and no balloon tip is shown. In addition,
Win32Exception states that "The operation completed successfully". Does
anyone have any ideas?
Many thanks
Ed Courtenay