ITPub博客

首页 > IT基础架构 > 网络安全 > 在托盘上显示Balloon Tooltip (转)

在托盘上显示Balloon Tooltip (转)

原创 网络安全 作者:worldblog 时间:2007-12-13 08:21:38 0 删除 编辑
在托盘上显示Balloon Tooltip (转)[@more@]

 

运行这个示例的前提是系统需要windows 2000 or xp shell version 5 or better)。
大家可能对托盘程序很熟悉了,这里我也不再多讲,这段小代码只是说明一下托盘的新特性:显示Balloon Tooltip。至于什么是Balloon Tooltip,只要把一下代码贴到VB中就会看到新鲜效果,再次提醒注意运行环境!

1.建立标准EXE工程,为Form1换一个PP的Icon,加入一个模块,改名为SysTray
SysTray.bas代码:

Option Explicit
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias _
  "Shell_NotifyIconA" (ByVal dwMessage As Long, _
  lpData As NOTIFYICONDATA) As Long

Public Type NOTIFYICONDATA
  cbSize As Long
  hwnd As Long
  uId As Long
  uFlags As Long
  uCallBackMessage As Long
  hIcon As Long
  szTip As String * 128
  dwState As Long
  dwStateMask As Long
  szInfo As String * 256
  uTimeoutOrVersion As Long  '由于VB中没有Union类型,只能用Long型代替
  szInfoTitle As String * 64
  dwInfoFlags As Long
End Type
 
Public Const NOTIFYICON_VERSION = 3
Public Const NOTIFYICON_OLDVERSION = 0

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

Public Const NIM_SETFOCUS = &H3
Public Const NIM_SETVERSION = &H4
 
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4

Public Const NIF_STATE = &H8
Public Const NIF_INFO = &H10
 
Public Const NIS_HIDDEN = &H1
Public Const NIS_SHAREDICON = &H2
 

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

Public nfIconData As NOTIFYICONDATA

2.Form1的代码:
Option Explicit

Private Sub Form_Load()
  With nfIconData
  .cbSize = Len(nfIconData)
  .hwnd = Me.hwnd
  .uId = vbNull
  .uFlags = NIF_INFO Or NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  .hIcon = Me.Icon
  .szTip = "你的小消息可以放在此..." & vbNullChar
  .dwState = 0
  .dwStateMask = 0
  .szInfo = "这是一个Balloon Style Tool-tip!又一个小技巧可以应用了  " & Chr(13) & ":)" & vbNullChar
  .uTimeoutOrVersion = 15000
  .szInfoTitle = "哈哈,看到了么" & vbNullChar
  .dwInfoFlags = NIIF_INFO
  End With

  Call Shell_NotifyIcon(NIM_ADD, nfIconData)
End Sub


Private Sub Form_Unload(Cancel As Integer)
  Call Shell_NotifyIcon(NIM_DELETE, nfIconData)
  End
End Sub

本程序代码使用vb6 + win2000调试通过


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-992457/,如需转载,请注明出处,否则将追究法律责任。

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