ITPub博客

首页 > 应用开发 > IT综合 > 在托盘上显示Balloon Tooltip(VB.NET) (转)

在托盘上显示Balloon Tooltip(VB.NET) (转)

原创 IT综合 作者:amyz 时间:2007-11-16 16:12:34 0 删除 编辑
在托盘上显示Balloon Tooltip(VB.NET) (转)[@more@]

使用VB编写在托盘上显示Balloon提示的功能就需要调用win32api了,但是vb6vb.NET代码上还是有些不同的,红色部分即为二者区别

Imports System.Runtime.InteropServices

Public Class Form1
  Inherits System.windows.Forms.Form


#Region "Win32Api_NotifyIcon"
  Private Declare Function shell_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 szTip As 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.object, 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" '& microsoft.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/10752019/viewspace-982625/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3984
  • 访问量
    7363004