473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Shell_NotifyIcon P/Invoke

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
Mar 14 '07 #1
3 6668
VJ
I am attaching a cs file that I wrote a while back with some help from
online fourm postings... Hope this will help what you want, and also there
is at the end of cs, a how to use section.. see that also..

This works for me well, and we use it in our applications. If have issues
let us know..!

VJ

"Ed Courtenay" <ed@reverse.yanetruocde.co.ukwrote in message
news:O6****************@TK2MSFTNGP05.phx.gbl...
>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


Mar 14 '07 #2
VJ wrote:
I am attaching a cs file that I wrote a while back with some help from
online fourm postings... Hope this will help what you want, and also there
is at the end of cs, a how to use section.. see that also..

This works for me well, and we use it in our applications. If have issues
let us know..!

VJ
Thanks for taking the time, but the attached code does not address the
issue I'm dealing with; namely that I wish to use Shell_Notify to raise
a balloon tip with it's own icon (i.e. not one of the standard
Windows-supplied Information, Warning or Error icons). This, as I've
stated, I've already achieved, but I can't get the function to use two
different icons - one for the Notification area and a separate one for
the ballooon, which the documentation suggests is possible by populating
both the hIcon and hBalloonIcon fields in the appropriate structure.

Any ideas?
Mar 14 '07 #3
VJ
aah ok.. try codeproject.com. There was sample there.

VJ

"Ed Courtenay" <ed@reverse.yanetruocde.co.ukwrote in message
news:ec**************@TK2MSFTNGP02.phx.gbl...
VJ wrote:
>I am attaching a cs file that I wrote a while back with some help from
online fourm postings... Hope this will help what you want, and also
there is at the end of cs, a how to use section.. see that also..

This works for me well, and we use it in our applications. If have issues
let us know..!

VJ

Thanks for taking the time, but the attached code does not address the
issue I'm dealing with; namely that I wish to use Shell_Notify to raise a
balloon tip with it's own icon (i.e. not one of the standard
Windows-supplied Information, Warning or Error icons). This, as I've
stated, I've already achieved, but I can't get the function to use two
different icons - one for the Notification area and a separate one for the
ballooon, which the documentation suggests is possible by populating both
the hIcon and hBalloonIcon fields in the appropriate structure.

Any ideas?

Mar 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Altland | last post by:
Here is my basic problem. I have a form that executes a cpu instensive algorithm occupying the first thread. When the algorithm is executed another form pops up telling the user the progress that...
1
by: boxim | last post by:
hi all, I'm having a few problems whereby my application is hanging when using the Invoke method of a form's control. Basically, when a user clicks a button on the form, it calls a remote...
2
by: Tom | last post by:
Hi Everybod I want to update some controls in a form from another threads. I did it by passing the form to that thread and calling a delegate with Form1.Invoke, I want to have just one delegeate...
5
by: RickDee | last post by:
Please help, anybody. I am trying to write a program so that it can launch an exe file ( which is also genereated in C# ) and then simulate the button clicking and invoke the methods inside the...
14
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values...
23
by: Thomas Due | last post by:
Hi, I have a class which monitors a TCP socket. This will on occasion raise an event which can be handled by a GUI. Now, I am aware of the if(InvokeRequire) { EventHandler d = new...
6
by: Dom | last post by:
I'm teaching myself about delegates and the Invoke method, and I have a few newbie questions for the gurus out there: Here are some CSharp statements: 1. public delegate void MyDelegate (int k,...
2
by: =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= | last post by:
vs2005, c# Trying to understand why one way works but the other doesnt. I have not tried to create a simpler mdi/child/showdialog app for posting purposes (I think even this would not be so small...
3
balabaster
by: balabaster | last post by:
I have a class that I want to make thread-safe and am investigating the ISyncronizeInvoke interface and wondering just what it will take to implement this interface. So far the basic concept of my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.