VB托盘代码问题
OptionExplicitConstMAX_TOOLTIPAsInteger=64ConstNIF_ICON=&H2ConstNIF_MESSAGE=&H1ConstN...
Option Explicit
Const MAX_TOOLTIP As Integer = 64
Const NIF_ICON = &H2
Const NIF_MESSAGE = &H1
Const NIF_TIP = &H4
Const NIM_ADD = &H0
Const NIM_DELETE = &H2
Const WM_MOUSEMOVE = &H200
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_LBUTTONDBLCLK = &H203
Const WM_RBUTTONDOWN = &H204
Const WM_RBUTTONUP = &H205
Const WM_RBUTTONDBLCLK = &H206
Const SW_RESTORE = 9
Const SW_HIDE = 0
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * MAX_TOOLTIP
End Type
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private nfIconData As NOTIFYICONDATA
Private Sub Form_Unload(Cancel As Integer)
Dim ky
If Check1.Value = 1 Then
ky = "111111111111" & vbNullChar
Else
ky = "22222222" & vbNullChar
End If
Cancel = 1
nfIconData.cbSize = Len(nfIconData)
nfIconData.uID = vbNull
nfIconData.hwnd = Me.hwnd
nfIconData.uFlags = NIF_TIP Or NIF_MESSAGE Or NIF_ICON
nfIconData.uCallbackMessage = WM_MOUSEMOVE
nfIconData.hIcon = Me.Icon
nfIconData.szTip = ky & vbNullChar
Shell_NotifyIcon NIM_ADD, nfIconData
Me.Hide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX
If lMsg = WM_LBUTTONUP Then
Me.WindowState = 0
Me.Show
Else
If lMsg = WM_RBUTTONUP Then
'PopupMenu Traymenu
End If
End If
End Sub
这里怎么才能改变
If Check1.Value = 1 Then
ky = "111111111111" & vbNullChar
Else
ky = "22222222" & vbNullChar
End If
托盘后打开重新选择Check1.后再托盘还是显示11111111111 展开
Const MAX_TOOLTIP As Integer = 64
Const NIF_ICON = &H2
Const NIF_MESSAGE = &H1
Const NIF_TIP = &H4
Const NIM_ADD = &H0
Const NIM_DELETE = &H2
Const WM_MOUSEMOVE = &H200
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_LBUTTONDBLCLK = &H203
Const WM_RBUTTONDOWN = &H204
Const WM_RBUTTONUP = &H205
Const WM_RBUTTONDBLCLK = &H206
Const SW_RESTORE = 9
Const SW_HIDE = 0
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * MAX_TOOLTIP
End Type
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private nfIconData As NOTIFYICONDATA
Private Sub Form_Unload(Cancel As Integer)
Dim ky
If Check1.Value = 1 Then
ky = "111111111111" & vbNullChar
Else
ky = "22222222" & vbNullChar
End If
Cancel = 1
nfIconData.cbSize = Len(nfIconData)
nfIconData.uID = vbNull
nfIconData.hwnd = Me.hwnd
nfIconData.uFlags = NIF_TIP Or NIF_MESSAGE Or NIF_ICON
nfIconData.uCallbackMessage = WM_MOUSEMOVE
nfIconData.hIcon = Me.Icon
nfIconData.szTip = ky & vbNullChar
Shell_NotifyIcon NIM_ADD, nfIconData
Me.Hide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX
If lMsg = WM_LBUTTONUP Then
Me.WindowState = 0
Me.Show
Else
If lMsg = WM_RBUTTONUP Then
'PopupMenu Traymenu
End If
End If
End Sub
这里怎么才能改变
If Check1.Value = 1 Then
ky = "111111111111" & vbNullChar
Else
ky = "22222222" & vbNullChar
End If
托盘后打开重新选择Check1.后再托盘还是显示11111111111 展开
2个回答
展开全部
原因分析:气泡响应的信息已经注入,不清除将无法覆盖
处理方法:删除原来的气泡,再传递新的值
'在这段加一行代码 XP +VB6 测试通过
Private Sub Form_Unload(Cancel As Integer)
Dim ky
If Check1.Value = 1 Then
ky = "111111111111" & vbNullChar
Else
ky = "22222222" & vbNullChar
End If
'===================下面是关键========================
Shell_NotifyIcon NIM_DELETE, nfIconData
'===================上面是关键========================
Cancel = 1
nfIconData.cbSize = Len(nfIconData)
nfIconData.uID = vbNull
nfIconData.hwnd = Me.hwnd
nfIconData.uFlags = NIF_TIP Or NIF_MESSAGE Or NIF_ICON
nfIconData.uCallbackMessage = WM_MOUSEMOVE
nfIconData.hIcon = Me.Icon
nfIconData.szTip = ky & vbNullChar
Shell_NotifyIcon NIM_ADD, nfIconData
Me.Hide
有疑问或测试不成功 请留言
处理方法:删除原来的气泡,再传递新的值
'在这段加一行代码 XP +VB6 测试通过
Private Sub Form_Unload(Cancel As Integer)
Dim ky
If Check1.Value = 1 Then
ky = "111111111111" & vbNullChar
Else
ky = "22222222" & vbNullChar
End If
'===================下面是关键========================
Shell_NotifyIcon NIM_DELETE, nfIconData
'===================上面是关键========================
Cancel = 1
nfIconData.cbSize = Len(nfIconData)
nfIconData.uID = vbNull
nfIconData.hwnd = Me.hwnd
nfIconData.uFlags = NIF_TIP Or NIF_MESSAGE Or NIF_ICON
nfIconData.uCallbackMessage = WM_MOUSEMOVE
nfIconData.hIcon = Me.Icon
nfIconData.szTip = ky & vbNullChar
Shell_NotifyIcon NIM_ADD, nfIconData
Me.Hide
有疑问或测试不成功 请留言
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询