473,394 Members | 1,759 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,394 software developers and data experts.

Tray Icon NotiFy Balloon Problem

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 set it. Where is the error?? Please Help
me. Thanks.

[code]
Imports System.Runtime.InteropServices
Public Class ClsNotifyBalloon
<StructLayout(LayoutKind.Sequential)> _
Public Structure NOTIFYICONDATA
Public cbSize As Integer
Public hwnd As IntPtr
Public uID As Integer
Public uFlags As Integer
Public uCallbackMessage As Integer
Public hIcon As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
Public szTip As String
Public dwState As Integer
Public dwStateMask As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
Public szInfo As String
Public uTimeout As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> _
Public szInfoTitle As String
Public dwInfoFlags As Integer
End Structure

<DllImport("Shell32")> _
Private Shared Function Shell_NotifyIconA(ByVal Msg As Integer,
ByRef Nd As NOTIFYICONDATA) As IntPtr
End Function

Public Enum ToolTipIcon
TTI_INFO = 1
TTI_WARNING = 2
TTI_ERROR = 3
End Enum

Public Sub DisplayBalloon(ByVal Caption As String, ByVal strText As
String, ByVal Ni As NotifyIcon, ByVal ico As ToolTipIcon, Optional
ByVal timeout As Integer = 1000)
Dim notifystruct As NOTIFYICONDATA
Dim nWindow As NativeWindow =
DirectCast(Ni.GetType.GetField("window",
Reflection.BindingFlags.NonPublic Or
Reflection.BindingFlags.Instance).GetValue(Ni), NativeWindow)

With notifystruct
.cbSize = 0
.dwInfoFlags = 0
.dwState = 0
.dwStateMask = 0
.hIcon = New IntPtr(0)
.szTip = String.Empty
.uCallbackMessage = &H200
.szInfoTitle = Caption
.uTimeout = timeout
.hwnd = nWindow.Handle
.uID = Convert.ToInt32(Ni.GetType.GetField("id",
Reflection.BindingFlags.NonPublic Or
Reflection.BindingFlags.Instance).GetValue(Ni))
.dwInfoFlags = Convert.ToInt32(ico)
.uTimeout = Environment.OSVersion.Version.Major
.szInfo = strText
.uFlags = &H10
.cbSize = Marshal.SizeOf(notifystruct)
Shell_NotifyIconA(&H1, notifystruct)
End With

End Sub

End Class

Nov 21 '05 #1
2 3509
I forgot to tell that the S.O. is Windows XP

Nov 21 '05 #2
well i use this one
Option Explicit On

Option Strict On

Imports System.Runtime.InteropServices

Public Class Balloon

<StructLayout(LayoutKind.Sequential)> _

Public Structure NOTIFYICONDATA

Public cbSize As Int32

Public hwnd As IntPtr

Public uID As Int32

Public uFlags As Int32

Public uCallbackMessage As IntPtr

Public hIcon As IntPtr

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _

Public szTip As String

Public dwState As Int32

Public dwStateMask As Int32

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _

Public szInfo As String

Public uTimeout As Int32

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> _

Public szInfoTitle As String

Public dwInfoFlags As Int32

End Structure

Public Const NIF_MESSAGE As Int32 = &H1

Public Const NIF_ICON As Int32 = &H2

Public Const NIF_STATE As Int32 = &H8

Public Const NIF_INFO As Int32 = &H10

Public Const NIF_TIP As Int32 = &H4

Public Const NIM_ADD As Int32 = &H0

Public Const NIM_MODIFY As Int32 = &H1

Public Const NIM_DELETE As Int32 = &H2

Public Const NIM_SETVERSION As Int32 = &H4

Public Const NOTIFYICON_VERSION As Int32 = &H5

Public Const NIIF_ERROR As Int32 = &H3

Public Const NIIF_INFO As Int32 = &H1

Public Const NIIF_NONE As Int32 = &H0

Public Const NIM_SETFOCUS As Int32 = &H3

Public Enum BalloonMessageType

None = &H0

Info = &H1

[Error] = &H3

End Enum

Shared Sub NotifyBalloon(ByRef ntfyIcon As NotifyIcon, ByVal Title As
String, ByVal Info As String, ByVal Type As BalloonMessageType, ByVal
Timeout As Integer)

Dim t As Type = GetType(NotifyIcon)

Dim window As IntPtr = (CType(t.GetField("window",
System.Reflection.BindingFlags.Instance Or
System.Reflection.BindingFlags.NonPublic).GetValue (ntfyIcon),
NativeWindow)).Handle

Dim id As Int32 = CType(t.GetField("id",
System.Reflection.BindingFlags.Instance Or
System.Reflection.BindingFlags.NonPublic).GetValue (ntfyIcon), Integer)

Dim uNIF As NOTIFYICONDATA

uNIF.cbSize = 0

uNIF.dwInfoFlags = 0

uNIF.dwState = 0

uNIF.dwStateMask = 0

uNIF.hIcon = IntPtr.Zero

uNIF.szTip = ""

uNIF.uCallbackMessage = New IntPtr(&H200)

uNIF.szInfoTitle = Title

uNIF.uTimeout = Timeout

uNIF.hwnd = window

uNIF.uID = id

uNIF.dwInfoFlags = CType(Type, Int32)

uNIF.uTimeout = NOTIFYICON_VERSION

uNIF.szInfo = Info

uNIF.uFlags = NIF_INFO

uNIF.cbSize = Marshal.SizeOf(uNIF)

Dim result As Int32 = Shell_NotifyIconA(NIM_MODIFY, uNIF)

End Sub

Private Declare Function Shell_NotifyIconA Lib "shell32" (ByVal dwMessage As
Int32, ByRef pnid As NOTIFYICONDATA) As Int32

End Class

and on windows 2003 i didn`t see anny strange behavior

regards

M. posseth [MCP]

"Andrea V.F." <vf******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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 set it. Where is the error?? Please Help
me. Thanks.

[code]
Imports System.Runtime.InteropServices
Public Class ClsNotifyBalloon
<StructLayout(LayoutKind.Sequential)> _
Public Structure NOTIFYICONDATA
Public cbSize As Integer
Public hwnd As IntPtr
Public uID As Integer
Public uFlags As Integer
Public uCallbackMessage As Integer
Public hIcon As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
Public szTip As String
Public dwState As Integer
Public dwStateMask As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
Public szInfo As String
Public uTimeout As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> _
Public szInfoTitle As String
Public dwInfoFlags As Integer
End Structure

<DllImport("Shell32")> _
Private Shared Function Shell_NotifyIconA(ByVal Msg As Integer,
ByRef Nd As NOTIFYICONDATA) As IntPtr
End Function

Public Enum ToolTipIcon
TTI_INFO = 1
TTI_WARNING = 2
TTI_ERROR = 3
End Enum

Public Sub DisplayBalloon(ByVal Caption As String, ByVal strText As
String, ByVal Ni As NotifyIcon, ByVal ico As ToolTipIcon, Optional
ByVal timeout As Integer = 1000)
Dim notifystruct As NOTIFYICONDATA
Dim nWindow As NativeWindow =
DirectCast(Ni.GetType.GetField("window",
Reflection.BindingFlags.NonPublic Or
Reflection.BindingFlags.Instance).GetValue(Ni), NativeWindow)

With notifystruct
.cbSize = 0
.dwInfoFlags = 0
.dwState = 0
.dwStateMask = 0
.hIcon = New IntPtr(0)
.szTip = String.Empty
.uCallbackMessage = &H200
.szInfoTitle = Caption
.uTimeout = timeout
.hwnd = nWindow.Handle
.uID = Convert.ToInt32(Ni.GetType.GetField("id",
Reflection.BindingFlags.NonPublic Or
Reflection.BindingFlags.Instance).GetValue(Ni))
.dwInfoFlags = Convert.ToInt32(ico)
.uTimeout = Environment.OSVersion.Version.Major
.szInfo = strText
.uFlags = &H10
.cbSize = Marshal.SizeOf(notifystruct)
Shell_NotifyIconA(&H1, notifystruct)
End With

End Sub

End Class

Nov 21 '05 #3

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

Similar topics

1
by: Sherry | last post by:
Is there a way to monitor system tray to wait for a specific icon (notifyIcon) or a specific balloon tip. I need write a program to wait for the balloon tip or the notifyIcon to show up, then...
10
by: Zeljko | last post by:
Hi, I have a form with a tray icon. However, when I minimize the form, it stays visible - not in the task bar (I have showintaskbar property set to false), but in a form of a rectangle sitting...
7
by: Danielb | last post by:
I want my application to run most of the time as just an notify icon visible in the system tray, with some dialogs windows that open if the user selects an option from the context menu on the tray...
0
by: sanjana | last post by:
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...
4
by: utkarsh | last post by:
Hi, I want to develop a Window Service in C# that should be capable of sisplaying the a icon in the window tray. Based on some logic in service, icon should be changed to some other...
5
by: BJ | last post by:
I am trying to add my application to the system tray. I am not using the built in control becuase of the limitation that you can not use the balloon tool tip feature. I have done this succesfully...
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...
2
by: Mythran | last post by:
There a way to add balloons to the system tray icons (our own) via C#/VB.Net 1.1? Thx, Mythran
5
by: =?Utf-8?B?QnJpYW4gRmFybmhpbGw=?= | last post by:
Hi, I'm trying to write a Windows App that will sit in the system tray. I don't need it to have any forms and UI to it really, just a context menu on the icon in the system tray that has links...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.