在托盤上顯示Balloon Tooltip(VB.NET) (轉)

worldblog發表於2007-08-16
在托盤上顯示Balloon Tooltip(VB.NET) (轉)[@more@]

使用VB編寫在托盤上顯示Balloon提示的功能就需要了,但是和程式碼上還是有些不同的,紅色部分即為二者區別

Imports System.Runtime.InteropServices

Public Class Form1
  Inherits System..Forms.Form


#Region "Win32Api_NotifyIcon"
  Private Declare Function _NotifyIcon Lib "shell32.dll" Alias _
  "Shell_NotifyIconA" (ByVal dwMessage As Int32, _
  ByRef lpData As NOTIFYICONDATA) As Int32

  Private Structure NOTIFYICONDATA
  Public cbSize As Int32
  Public hwnd As IntPtr
  Public uId As Int32
  Public uFlags As Int32
  Public uCallBackMessage As Int32
  Public hIcon As IntPtr
  _
  Public szTAs String
  Public dwState As Int32
  Public dwStateMask As Int32
  _
  Public szInfo As String
  Public uTimeoutOrVersion As Int32
  _
  Public szInfoTitle As String
  Public dwInfoFlags As Int32
  End Structure

  Private Const NOTIFYICON_VERSION = 3
  Private Const NOTIFYICON_OLDVERSION = 0

  Private Const NIM_ADD = &H0
  Private Const NIM_MODIFY = &H1
  Private Const NIM_DELETE = &H2

  Private Const NIM_SETFOCUS = &H3
  Private Const NIM_SETVERSION = &H4

  Private Const NIF_MESSAGE = &H1
  Private Const NIF_ICON = &H2
  Private Const NIF_TIP = &H4

  Private Const NIF_STATE = &H8
  Private Const NIF_INFO = &H10

  Private Const NIS_HIDDEN = &H1
  Private Const NIS_SHAREDICON = &H2


  Private Const NIIF_NONE = &H0
  Private Const NIIF_WARNING = &H2
  Private Const NIIF_ERROR = &H3
  Private Const NIIF_INFO = &H1

  Private nfIconData As NOTIFYICONDATA

#End Region


  Private Sub Form1_Load(ByVal sender As System., ByVal e As System.EventArgs) Handles MyBase.Load
  nfIconData = New NOTIFYICONDATA()
  With nfIconData
  .cbSize = System.Runtime.InteropServices.Marshal.SizeOf(nfIconData)
  .hwnd = Me.Handle
  .uId = vbNull
  .uFlags = NIF_INFO Or NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  .hIcon = Me.Icon.Handle
  .szTip = "123" '& .VisualBasic.vbNullChar
  .dwState = 0
  .dwStateMask = 0
  .szInfo = "Balloon Style Tool-tip" & Chr(13) & "哈哈" '& vbNullChar
  .uTimeoutOrVersion = 15000
  .szInfoTitle = "看到了麼?" '& Microsoft.VisualBasic.vbNullChar
  .dwInfoFlags = NIIF_INFO
  End With


  Call Shell_NotifyIcon(NIM_ADD, nfIconData)

  End Sub

  Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
  Call Shell_NotifyIcon(NIM_DELETE, nfIconData)
  End Sub
End Class


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-962117/,如需轉載,請註明出處,否則將追究法律責任。

相關文章