Click to See Complete Forum and Search --> : Systray


pueromane
November 18th, 1999, 01:56 PM
How can I write a program which is not shown in the Task Bar but has an Icon in the SysTray.

Please help

mfG Pueromane

Aaron Young
November 18th, 1999, 11:35 PM
Add this to a Form with an Invisible Picturebox and Set the ShowInTaskBar Property to False.

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 Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (byval dwMessage as Long, lpData as NOTIFYICONDATA) as Long

private Const NIF_ICON = &H2
private Const NIF_MESSAGE = &H1
private Const NIF_TIP = &H4
private Const NIM_ADD = &H0
private Const NIM_DELETE = &H2
private Const NIM_MODIFY = &H1
private Const WM_MOUSEMOVE = &H200
private Const WM_LBUTTONDBLCLK = &H203
private Const WM_LBUTTONDOWN = &H201
private Const WM_RBUTTONDOWN = &H204

private tTrayIcon as NOTIFYICONDATA

private Sub Form_Load()
'Create a Tray Icon
Picture1.Visible = false
With tTrayIcon
.hIcon = Icon
.hwnd = Picture1.hwnd
.szTip = "My Tray Icon" & Chr(0)
.uCallbackMessage = WM_MOUSEMOVE
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uID = 1
.cbSize = len(tTrayIcon)
End With
Shell_NotifyIcon NIM_ADD, tTrayIcon
End Sub

private Sub Form_Resize()
DoEvents
If WindowState = vbMinimized then
Hide
End If
End Sub

private Sub Form_Unload(Cancel as Integer)
'Remove the Tray Icon
Shell_NotifyIcon NIM_DELETE, tTrayIcon
End Sub

private Sub Picture1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
Select Case ScaleX(X, vbTwips, vbPixels)
Case WM_RBUTTONDOWN
'Show Popup Menu
Case WM_LBUTTONDBLCLK
'Show the Form
WindowState = vbNormal
Show
End Select
End Sub




Aaron Young
Analyst Programmer
adyoung@win.bright.net
aarony@redwingsoftware.com

pueromane
November 19th, 1999, 04:36 AM
Thanks it works fine

mfg Pueromane

Mikesc
November 19th, 1999, 09:40 AM
I don't follow how the Select Case statement works here. Why would the ScaleX function return a match to the button click constants?

Thanks in advance.

Aaron Young
November 19th, 1999, 11:40 AM
Because in the TrayIcon Structure we are telling it to send all Messages to the Picturebox Window Handle, and we tell it to use the WM_MOUSEMOVE Message, which triggers the Picture1_MouseMove() Event, because of this it is now passing the wParam and lParam Values Which end up in the X Parameter.
In Order to get the Value of the wParam which is a Long Data Type, we Get the Result of X in Pixels.


Aaron Young
Analyst Programmer
adyoung@win.bright.net
aarony@redwingsoftware.com