472,961 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

notify icon n balloon tip HELP urgent

hi
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;

#endregion

[DllImport("shell32.Dll")]
public static extern System.Int32 Shell_NotifyIcon(NotifyCommand cmd,
ref NotifyIconData data);

[DllImport("Kernel32.Dll")]
public static extern System.UInt32 GetCurrentThreadId();

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

[DllImport("user32.Dll")]
public static extern System.Int32 EnumThreadWindows(System.UInt32
threadId, EnumThreadWndProc callback, System.UInt32 param);

[DllImport("user32.Dll")]
public static extern System.Int32 GetClassName(System.IntPtr hWnd,
System.Text.StringBuilder className, System.Int32 maxCount);

#region Structure NotifyIconData
[StructLayout(LayoutKind.Sequential)]
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
}
#endregion

#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)
{
try
{
bool blnVersionOk = false;
blnVersionOk = this.GetShell32VersionInfo() >= 5;
if(blnVersionOk)
{
// 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);
//MessageBox.Show(q.ToString()+k.ToString());
}
}
catch(Exception objException)
{
throw new ApplicationException(objException.Message);
}
}
#endregion

#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}
#endregion
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)
{
try
{

ShowBalloon(1, "Updates", "Updates Available", 15000);
}
catch(Exception objException)
{
//MessageBox.Show(objException.Message);
throw new ApplicationException(objException.Message);
}
}


thanx

Nov 17 '05 #1
0 2495

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

Similar topics

3
by: jm | last post by:
Hi, I have a C# program that changes the notifyIcon during the program. What I have noticed is that sometimes when the program is over the old icon will still be in the system tray. But when i...
1
by: Rob | last post by:
I have an interesting problem with my Notify Icon. I cannot get it to display when I start a web service. I have no problems when I test the software on a Windows program. But the Icon will not...
2
by: Andrea V.F. | last post by:
I use the code below (VB.NET) to display a Popup balloon in the Tray Icon of my application. The balloon is displayed, but the timeout never happens and the balloon is always visible even if I...
2
by: Dave Booker | last post by:
I create a balloon tip in the system tray using: notify.ShowBalloonTip(10000, "Text", "More Text", ToolTipIcon.Info); After the time expires I want the icon to go away. The balloon disappears,...
6
by: Amongin Ewinyu | last post by:
Hi, I have an application that is controlled by a service. when the service starts, an icon is supposed to be placed in the system tray and this icon is then used to display a balloon...
0
by: Mike Eaton | last post by:
Hi there, I have an app whose structure is as follows: a module calls a custom application context containing a notify icon and associated context menu, which in turn acts upon an instance of...
1
by: DBC User | last post by:
I have a windows form and I added a notify icon. In there I have following 2 lines notifyIcon.ShowBaloonTip(1000,"test", msg, ToolTipIcon.Info); I stepped through the code and it executed...
3
by: Cylix | last post by:
I am going to make an application in monitor and do something on time. A part of it is an Notify icon(System Tray Icon), Which project type can I be used for Just showing the notify icon without...
2
by: mr t | last post by:
Hi guys, I have a notify Icon, but when I call showBallonTip, the balloon does not show. any reason why? here is my call: Me.NotMemberServ.ShowBalloonTip(5000, "New Member IDs", iCountNew & "...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.