A
Andrea V.F.
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.
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