PDA

Click to See Complete Forum and Search --> : Application in SystemTray?


madd indian
Jan 22nd, 2000, 05:12 AM
How can I make my application go in the system tray when the 'minimize button' is clicked?

What's the code to make it go in the System Tray?

Lior
Jan 22nd, 2000, 05:27 AM
Hey man...
In order to put your program in Win98's system tray, you need to use the Windows API.
Here is a piece of code that should help you:

Option Explicit
Private 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

Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4

Private Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid _
As NOTIFYICONDATA) As Boolean

Dim t As NOTIFYICONDATA

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

Timer1.Enabled = False

t.cbSize = Len(t)
t.hWnd = Picture1.hWnd
t.uId = 1&

Shell_NotifyIcon NIM_DELETE, t

End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Hex(X) = "1E3C" Then
Me.PopupMenu menu1
End If

End Sub

Private Sub Timer1_Timer()
Static i As Long, img As Long
t.cbSize = Len(t)
t.hWnd = Picture1.hWnd
t.uId = 1&
t.uFlags = NIF_ICON
t.hIcon = Picture1.Picture
Shell_NotifyIcon NIM_MODIFY, t
Timer1.Enabled = True
i = i + 1
If i = 2 Then i = 0
End Sub

Private Sub Form_Load()

t.cbSize = Len(t)
t.hWnd = Picture1.hWnd
t.uId = 1&
t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
t.ucallbackMessage = WM_MOUSEMOVE
t.hIcon = Picture1.Picture
t.szTip = "System Tray" & Chr$(0)

Shell_NotifyIcon NIM_ADD, t

Timer1.Enabled = True

Me.Hide

App.TaskVisible = False

End Sub



------------------
------
God:
------
Oh...those israeli programmers..!

madd indian
Jan 23rd, 2000, 02:26 AM
I copied and pasted the code into my project and drew the necessary controls but it still didn't work. Gave some error about "t" not being a defined type or something.

madd indian
Jan 23rd, 2000, 11:10 AM
Thank you,

But why do you have a timer and a picture box in there?

[This message has been edited by madd indian (edited 01-23-2000).]

rino_2
Jan 23rd, 2000, 11:12 AM
I think that the picture box hold the image that will be displyed in the System Tray?