|
-
May 21st, 2001, 03:32 AM
#1
Thread Starter
Hyperactive Member
refresh system tray
i have my application siting in the system tray. If i exit, the icon stays there until i move the mouse over the tray and it's refreshed.
is there a way i can force refreshing of the tray?
-
May 21st, 2001, 09:26 AM
#2
Lively Member
You Should Add the NIM_DELETE to Destroy the Tray Icon
Try this Code...
' Module Code
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
' Types for Adding, Modifying and Deleting Tray Icon...
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
' Constants for Mouse Move Events..
Public Const WM_MOUSEMOVE = &H200
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
Public Const WM_LBUTTONDOWN = &H201 'Button down
Public Const WM_LBUTTONUP = &H202 'Button up
Public Const WM_RBUTTONDBLCLK = &H206 'Double-click
Public Const WM_RBUTTONDOWN = &H204 'Button down
Public Const WM_RBUTTONUP = &H205 'Button up
'Declare the API function call.
Public cnter as Integer
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
' Form Code
Private sub Form_Load()
Dim Nid as NOTIFYICONDATA
With Nid
.cbSize = Len(nid)
.hWnd = Form1.hWnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Form1.Icon
.szTip = "Tray Icon Sample Program" & vbNullChar
end With
Shell_NotifyIcon NIM_ADD, Nid
End Sub
Private Sub Form_Unload()
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Private Sub Form_MouseMove _
(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
'Event occurs when the mouse pointer is within the rectangular
'boundaries of the icon in the taskbar status area.
Dim msg As Long
Dim sFilter As String
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
CommonDialog1.DialogTitle = "Select an Icon"
sFilter = "Icon Files (*.ico)|*.ico"
sFilter = sFilter & "|All Files (*.*)|*.*"
CommonDialog1.Filter = sFilter
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Form1.Icon = LoadPicture(CommonDialog1.FileName)
nid.hIcon = Form1.Icon
Shell_NotifyIcon NIM_MODIFY, nid
End If
Case WM_RBUTTONDOWN
Dim ToolTipString As String
ToolTipString = InputBox("Enter the new ToolTip:", "Change ToolTip")
If ToolTipString <> "" Then
nid.szTip = ToolTipString & vbNullChar
Shell_NotifyIcon NIM_MODIFY, nid
End If
Case WM_RBUTTONUP
Case WM_RBUTTONDBLCLK
End Select
End Sub
' To Animate a Tray Icon you've to Add a Timer with Interval as required use the Following Code in the Timer. Add 4 Picture Boxes with Different Pictures and Add the Following Code...
Private Sub Timer1_Timer()
cnter = cnter + 1
Select Case cnter
Case 1
Form1.Icon = Picture1.Picture
nid.hIcon = Form1.Icon
Shell_NotifyIcon NIM_MODIFY, nid
Case 2
Form1.Icon = Picture2.Picture
nid.hIcon = Form1.Icon
Shell_NotifyIcon NIM_MODIFY, nid
Case 3
Form1.Icon = Picture3.Picture
nid.hIcon = Form1.Icon
Shell_NotifyIcon NIM_MODIFY, nid
Case 4
Form1.Icon = Picture4.Picture
nid.hIcon = Form1.Icon
Shell_NotifyIcon NIM_MODIFY, nid
Case Is >= 4
cnter = 0
End Select
End Sub
-
May 21st, 2001, 09:29 AM
#3
Addicted Member
Here's the code from one of my own programs, a standalone spell checker that has a system tray icon. I'm assuming you used the API to get it there in the first place...
In Form_Unload:
' Remove the icon from the sys tray
Dim nid as NOTIFYICONDATA
With nid
.hWnd = Me.hWnd ' You're refering to messages sent to your window
.cbSize = Len(nid)
.uID = 0
End With
Shell_NotifyIconA NIM_DELETE, nid
' set the window procedure back to the original
SetWindowLongA Me.hWnd, -4, oldproc
DoEvents
End
// End code
Your API declarations and window procedure variables probably look different, I just dropped in this code from somewhere (probably www.freevbcode.com). This will remove the icon from the tray, unless your program unexpectedly crashes. If you need more, let me know!
Things I've Said:
"Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
"Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
"You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"
-
May 21st, 2001, 09:35 AM
#4
Lively Member
I think This is Not Necessary (SetWindowLongA Me.hWnd, -4, oldproc )
Hi csammis,
I think this is not needed. Just the NIM_DELETE will do...
-
May 22nd, 2001, 07:05 AM
#5
Thread Starter
Hyperactive Member
-
May 22nd, 2001, 05:01 PM
#6
Addicted Member
To lvramanan:
You're right, it's not needed if the programs about to exit anyway, but it's good coding practice to put the window proc back when you're done. Plus, if you do that in the VB IDE it crashes VB (since your program at that point is still part of VB, so the program's window proc is run through VB's proc...if VB loses it's proc, it shuts down hard).
Things I've Said:
"Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
"Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
"You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|