PDA

Click to See Complete Forum and Search --> : Running in the System Tray


Electron
Nov 27th, 1999, 04:57 AM
Does anyone have any suggestions on how to a program in the System Tray, like where the Volume Control and Clock runs, instead of the Task Bar?

Thanks for your help!

Jeff

Aaron Young
Nov 27th, 1999, 10:56 AM
Add an Invisible Picturebox to your Form 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
aarony@redwingsoftware.com
adyoung@win.bright.net

Quadrex
Nov 28th, 1999, 04:38 AM
Who do you make a PopMenu appear though.

Any help would be greatly appreitiated,



------------------
Quadrex
webmaster@quadrex.f9.co.uk
Quadrex Programming (http://www.quadrex.f9.co.uk)

Aaron Young
Nov 28th, 1999, 07:10 AM
Make a Standard Menu on the Form using the Menu Editor, then set the Menu's visible Property to False, (Unchecked), then in the Right Click Section of the Code I posted, use:

Me.PopupMenu mnuPopup

Where mnuPopup is the Name of your Invisible Menu.


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