Hi. Ich habe lange nach einen Code gesucht, womit man nur ein Icon im Tray hat, wo ein Contextmenü UND Balloon-Popups mitgehen.
ich habe das jetzt gefunden. Ich denke das ich das hier posten sollte, da ich es nicht im Forum findne konnte, und ich es für wichtig finde. Und Sourcecode ist immergut !
Modul:
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 Erstellt nun ein NotifyIcon (bei mir NotifyIcon1), optionell könnt ihr das jetzt mit einem Context Menü austatten. Der Aufruf für eine Balloon Box:
Balloon.NotifyBalloon(NotifyIcon1, "Überschrift", ""Text", DAUER) Hoffe das es euch hilft. Finde den Code super.
Gr??e
[AP!]
P.S.
Ich habe MSN, falls nochjemand MSN haben sollte, kann er mich ja addedn, dann k?nnen wir mal ?ber MSN labbern |