470,604 Members | 2,056 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

notify icon n balloon tip HELP urgent

i want to write a C# .net code to display a balloon in the task bar
i have used notifyicon class to get the icon in the task bar
then i have used Shell_NotifyIcon and NotifyIconData structure for
getting the balloon
So now i have an icon n a balloon in the task bar

But i wan tht when i click on the yellow windows balloon an event
should be fired
I know tht i have to use NIN_BALLOONUSERCLICK of Shell_NotifyIcon for
achieving this
but still i am not getting it exactly
i tried it but cudnt proceed
can anyone help me as to how to fire event on click of the ballon

Main class which displays icon and balloon code snippet:
private const Int32 NOTIFYICON_VERSION = 3;


public static extern System.Int32 Shell_NotifyIcon(NotifyCommand cmd,
ref NotifyIconData data);

public static extern System.UInt32 GetCurrentThreadId();

public delegate System.Int32 EnumThreadWndProc(System.IntPtr hWnd,
System.UInt32 lParam);

public static extern System.Int32 EnumThreadWindows(System.UInt32
threadId, EnumThreadWndProc callback, System.UInt32 param);

public static extern System.Int32 GetClassName(System.IntPtr hWnd,
System.Text.StringBuilder className, System.Int32 maxCount);

#region Structure NotifyIconData
public struct NotifyIconData
public System.UInt32 cbSize; // DWORD
public System.IntPtr hWnd; // HWND
public System.UInt32 uID; // UINT
public NotifyFlags uFlags; // UINT
public System.UInt32 uCallbackMessage; // UINT
public System.IntPtr hIcon; // HICON
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
public System.String szTip; // char[128]
public System.UInt32 dwState; // DWORD
public System.UInt32 dwStateMask; // DWORD
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public System.String szInfo; // char[256]
public System.UInt32 uTimeoutOrVersion; // UINT
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
public System.String szInfoTitle; // char[64]
public System.UInt32 dwInfoFlags; // DWORD

#region ShowBalloon
/// <summary>
/// displays the taskbar balloon message
/// </summary>
/// <param name="uintIconID"></param>
/// <param name="strTitle"></param>
/// <param name="strText"></param>
/// <param name="uintTimeout"></param>
public void ShowBalloon(uint uintIconID, string strTitle, string
strText, uint uintTimeout)
bool blnVersionOk = false;
blnVersionOk = this.GetShell32VersionInfo() >= 5;
// get the current thread ID
uint uintThreadId = GetCurrentThreadId();

Type objType= m_objNotifyIcon.GetType();

IntPtr intPtrWindow =
((NativeWindow)objType.GetField("window",System.Re flection.BindingFlags.Instance
System.Reflection.BindingFlags.NonPublic).GetValue (m_objNotifyIcon)).Handle;
int intID
=(int)objType.GetField("id",System.Reflection.Bind ingFlags.Instance |
System.Reflection.BindingFlags.NonPublic).GetValue (m_objNotifyIcon);

// show the balloon
NotifyIconData objData = new NotifyIconData();
objData.cbSize =
(System.UInt32)System.Runtime.InteropServices.Mars hal.SizeOf(typeof(NotifyIconData));
objData.hWnd = intPtrWindow;
objData.uID = (UInt32)intID;
objData.uFlags = NotifyFlags.Info;
//objData.uTimeoutOrVersion =uintTimeout;
objData.uTimeoutOrVersion =NOTIFYICON_VERSION ;
objData.szInfo = strText;
objData.szInfoTitle = strTitle;
int q=Shell_NotifyIcon(NotifyCommand.SetVersion,ref objData);
int k=Shell_NotifyIcon(NotifyCommand.Modify, ref objData);
catch(Exception objException)
throw new ApplicationException(objException.Message);

#region enum
public enum NotifyCommand {Add = 0, Modify = 1, Delete = 2, SetFocus
= 3, SetVersion = 4}
public enum NotifyFlags {Message = 1, Icon = 2, Tip = 4, State = 8,
Info = 16, Guid = 32}
Form1 has notify icon which appears in task bar and its double click
event shows the ablloon

#region NotifyIcon_Click
private void NotifyIcon_Click(object sender, System.EventArgs e)

ShowBalloon(1, "Updates", "Updates Available", 15000);
catch(Exception objException)
throw new ApplicationException(objException.Message);


Nov 17 '05 #1
0 2317

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by jm | last post: by
1 post views Thread by Rob | last post: by
2 posts views Thread by Andrea V.F. | last post: by
2 posts views Thread by Dave Booker | last post: by
6 posts views Thread by Amongin Ewinyu | last post: by
reply views Thread by Mike Eaton | last post: by
1 post views Thread by DBC User | last post: by
3 posts views Thread by Cylix | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.