dgb
asked on
Systray won't refresh after removing icon
Systray won't refresh after removing icon
Can you please show us how you attempted to add/remove your tray icon?
ASKER
Public Sub AddAppInTray(ByVal aHwnd As Long, _
ByVal anIconHandle As Long, _
ByVal aToolTipText As String)
' Set required properties
mNotifyIconData.cbSize = Len(mNotifyIconData)
mNotifyIconData.hwnd = aHwnd
mNotifyIconData.uId = vbNull
mNotifyIconData.uFlags = cNIF_ICON Or cNIF_TIP Or cNIF_MESSAGE
mNotifyIconData.uCallBackM essage = cWM_MOUSEMOVE
mNotifyIconData.hIcon = anIconHandle
' Chr$(0) is required at the end of the string
mNotifyIconData.szTip = aToolTipText & vbNullChar
' Finally put the app in the tray...
Shell_NotifyIcon cNIM_ADD, mNotifyIconData
mAppInTray = True
End Sub
Public Sub RemoveAppFromTray()
' Only remove the app from the tray if it's in it...
If mAppInTray Then
Shell_NotifyIcon cNIM_DELETE, mNotifyIconData
End If
End Sub
ByVal anIconHandle As Long, _
ByVal aToolTipText As String)
' Set required properties
mNotifyIconData.cbSize = Len(mNotifyIconData)
mNotifyIconData.hwnd = aHwnd
mNotifyIconData.uId = vbNull
mNotifyIconData.uFlags = cNIF_ICON Or cNIF_TIP Or cNIF_MESSAGE
mNotifyIconData.uCallBackM
mNotifyIconData.hIcon = anIconHandle
' Chr$(0) is required at the end of the string
mNotifyIconData.szTip = aToolTipText & vbNullChar
' Finally put the app in the tray...
Shell_NotifyIcon cNIM_ADD, mNotifyIconData
mAppInTray = True
End Sub
Public Sub RemoveAppFromTray()
' Only remove the app from the tray if it's in it...
If mAppInTray Then
Shell_NotifyIcon cNIM_DELETE, mNotifyIconData
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I do exactly what you've put in your example
(with my own names but the same idea)
I've looked around and it seems that more people have the same problem.
Program is gone icon is still there, when i place my mousepointer over it it disapears.
What i am looking fore is a way to refresh the systray
(with my own names but the same idea)
I've looked around and it seems that more people have the same problem.
Program is gone icon is still there, when i place my mousepointer over it it disapears.
What i am looking fore is a way to refresh the systray
This is a very interesting question. I don't know the answer myself, but experienced this behaviour a lot of times before with other (professional) programs, like the Norton virus scanner; the icon stays in the system tray, even though the program is killed/quit. Indeed, when you move your mouse over it, it disappears.
<<this post is just to get e-mail notifications about this question>>
<<this post is just to get e-mail notifications about this question>>
When I remove the Icon on my system via code it automatically disappears on my system.
One difference I spotted was that I am assigning a uID:
tic.uID = 1&
while you were not:
mNotifyIconData.uId = vbNull
Can you build a NEW project with my directions and code and see if it reacts differently?
One difference I spotted was that I am assigning a uID:
tic.uID = 1&
while you were not:
mNotifyIconData.uId = vbNull
Can you build a NEW project with my directions and code and see if it reacts differently?
ASKER
I've changed vbNull into 1& but nothing changed.
ASKER
I have to go but i will be back first thing tomorrow
Please try a NEW project with my code and directions and let us know how it behaves...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Leo, how does a weight loss supplement help?! Lol...
..... no comment.
and I lost the original link I had for you. Wooptie Doo!
: /
and I lost the original link I had for you. Wooptie Doo!
: /
ASKER
I have changed the location of "RemoveAppFromTray".
it is now the first thing i do when the user stops the program.
I will use the rest of the day to check it this is the answer.
After that i will devide the points (any suggestions)
it is now the first thing i do when the user stops the program.
I will use the rest of the day to check it this is the answer.
After that i will devide the points (any suggestions)
I don't have too much experience with this but these examples might help
Example 1
in a form :
' 'on the form1
Private Sub GoSystemTray()
VBGTray.cbSize = Len(VBGTray)
VBGTray.hwnd = Me.hwnd
VBGTray.uId = vbNull
VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
VBGTray.ucallbackMessage = WM_MOUSEMOVE
VBGTray.hIcon = Me.Icon
' 'tooltiptext
VBGTray.szTip = Me.Caption & vbNullChar
Call Shell_NotifyIcon(NIM_ADD, VBGTray)
App.TaskVisible = False 'remove application from taskbar
Me.Hide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static lngMsg As Long
Static blnFlag As Boolean
Dim result As Long
lngMsg = X / Screen.TwipsPerPixelX
If blnFlag = False Then
blnFlag = True
Select Case lngMsg
' 'doubleclick
Case WM_LBUTTONDBLCLICK
Me.Show
' 'right-click
Case WM_RBUTTONUP
result = SetForegroundWindow(Me.hwn d)
Me.PopupMenu mnuSystemtray
End Select
blnFlag = False
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
VBGTray.cbSize = Len(VBGTray)
VBGTray.hwnd = Me.hwnd
VBGTray.uId = vbNull
Call Shell_NotifyIcon(NIM_DELET E, VBGTray)
End Sub
in a module:
Public Const WM_LBUTTONDBLCLICK = &H203
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE = &H200
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Public VBGTray As NOTIFYICONDATA
Declare Function Shell_NotifyIcon Lib "shell32" Alias _
"Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Example 2
Public Const WM_LBUTTONDBLCLICK = &H203
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE = &H200
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Public VBGTray As NOTIFYICONDATA
Declare Function Shell_NotifyIcon Lib "shell32" Alias _
"Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
'************************* ********** ********** ********** *********
' Name: Windows 95 System Tray
' Description:Place your app's icon in the windows 95 system
' tray!
' 'thanxs to arno pijnappels
' 'modifications also by Rich Jones <rich_jones@wmg.com>
' By: Found on the World Wide Web
'
' Inputs:None
' Returns:None
' Assumes:None
' Side Effects:None
'
'Code provided by Planet Source Code(tm) 'as is', without
' warranties as to performance, fitness, merchantability,
' and any other warranty (whether expressed or implied).
'************************* ********** ********** ********** *********
' 'on the form1
Private Sub GoSystemTray()
VBGTray.cbSize = Len(VBGTray)
VBGTray.hWnd = Me.hWnd
VBGTray.uId = vbNull
VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
VBGTray.ucallbackMessage = WM_MOUSEMOVE
VBGTray.hIcon = Me.Icon
' 'tooltiptext
VBGTray.szTip = Me.Caption & vbNullChar
Call Shell_NotifyIcon(NIM_ADD, VBGTray)
App.TaskVisible = False'remove application from taskbar
Me.Hide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static lngMsg As Long
Static blnFlag As Boolean
Dim result As Long
lngMsg = X / Screen.TwipsPerPixelX
If blnFlag = False Then
blnFlag = True
Select Case lngMsg
' 'doubleclick
Case WM_LBUTTONDBLCLICK
Me.Show
' 'right-click
Case WM_RBUTTONUP
result = SetForegroundWindow(Me.hwn d)
Me.PopupMenu mnuSystemtray
End Select
blnFlag = False
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
VBGTray.cbSize = Len(VBGTray)
VBGTray.hWnd = Me.hWnd
VBGTray.uId = vbNull
Call Shell_NotifyIcon(NIM_DELET E, VBGTray)
End Sub
Maybe somewhere in there you can find your solution
Hope that helps,
Leo
Example 1
in a form :
' 'on the form1
Private Sub GoSystemTray()
VBGTray.cbSize = Len(VBGTray)
VBGTray.hwnd = Me.hwnd
VBGTray.uId = vbNull
VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
VBGTray.ucallbackMessage = WM_MOUSEMOVE
VBGTray.hIcon = Me.Icon
' 'tooltiptext
VBGTray.szTip = Me.Caption & vbNullChar
Call Shell_NotifyIcon(NIM_ADD, VBGTray)
App.TaskVisible = False 'remove application from taskbar
Me.Hide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static lngMsg As Long
Static blnFlag As Boolean
Dim result As Long
lngMsg = X / Screen.TwipsPerPixelX
If blnFlag = False Then
blnFlag = True
Select Case lngMsg
' 'doubleclick
Case WM_LBUTTONDBLCLICK
Me.Show
' 'right-click
Case WM_RBUTTONUP
result = SetForegroundWindow(Me.hwn
Me.PopupMenu mnuSystemtray
End Select
blnFlag = False
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
VBGTray.cbSize = Len(VBGTray)
VBGTray.hwnd = Me.hwnd
VBGTray.uId = vbNull
Call Shell_NotifyIcon(NIM_DELET
End Sub
in a module:
Public Const WM_LBUTTONDBLCLICK = &H203
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE = &H200
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Public VBGTray As NOTIFYICONDATA
Declare Function Shell_NotifyIcon Lib "shell32" Alias _
"Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Example 2
Public Const WM_LBUTTONDBLCLICK = &H203
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE = &H200
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Public VBGTray As NOTIFYICONDATA
Declare Function Shell_NotifyIcon Lib "shell32" Alias _
"Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
'*************************
' Name: Windows 95 System Tray
' Description:Place your app's icon in the windows 95 system
' tray!
' 'thanxs to arno pijnappels
' 'modifications also by Rich Jones <rich_jones@wmg.com>
' By: Found on the World Wide Web
'
' Inputs:None
' Returns:None
' Assumes:None
' Side Effects:None
'
'Code provided by Planet Source Code(tm) 'as is', without
' warranties as to performance, fitness, merchantability,
' and any other warranty (whether expressed or implied).
'*************************
' 'on the form1
Private Sub GoSystemTray()
VBGTray.cbSize = Len(VBGTray)
VBGTray.hWnd = Me.hWnd
VBGTray.uId = vbNull
VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
VBGTray.ucallbackMessage = WM_MOUSEMOVE
VBGTray.hIcon = Me.Icon
' 'tooltiptext
VBGTray.szTip = Me.Caption & vbNullChar
Call Shell_NotifyIcon(NIM_ADD, VBGTray)
App.TaskVisible = False'remove application from taskbar
Me.Hide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static lngMsg As Long
Static blnFlag As Boolean
Dim result As Long
lngMsg = X / Screen.TwipsPerPixelX
If blnFlag = False Then
blnFlag = True
Select Case lngMsg
' 'doubleclick
Case WM_LBUTTONDBLCLICK
Me.Show
' 'right-click
Case WM_RBUTTONUP
result = SetForegroundWindow(Me.hwn
Me.PopupMenu mnuSystemtray
End Select
blnFlag = False
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
VBGTray.cbSize = Len(VBGTray)
VBGTray.hWnd = Me.hWnd
VBGTray.uId = vbNull
Call Shell_NotifyIcon(NIM_DELET
End Sub
Maybe somewhere in there you can find your solution
Hope that helps,
Leo
ASKER
Leo:
Thanks but i hope it is already solved
(see comment just above yours)
Thanks but i hope it is already solved
(see comment just above yours)
Yeah I saw that. Just incase it doesn't work you can try to extract some code from above.
Happy coding : )
Leo
Happy coding : )
Leo
split
Leo
Leo
Hi Dan,
Quote dgb:
>I will use the rest of the day to check it this is the answer.
>After that i will devide the points (any suggestions)
Another quote:
>Thanks but i hope it is already solved
Points however, have never been split in the end...
Quote dgb:
>I will use the rest of the day to check it this is the answer.
>After that i will devide the points (any suggestions)
Another quote:
>Thanks but i hope it is already solved
Points however, have never been split in the end...