VB program in system tray

How can a VB program execute so that it appears minimized in the system tray, and displays a custom pop-up menu when clicked?
BobC042297Asked:
Who is Participating?
 
vinnyd79Connect With a Mentor Commented:
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 Const WM_LBUTTONDBLCLK = &H203   'Double-click
Private Const WM_LBUTTONDOWN = &H201     'Button down
Private Const WM_LBUTTONUP = &H202       'Button up
Private Const WM_RBUTTONDBLCLK = &H206   'Double-click
Private Const WM_RBUTTONDOWN = &H204     'Button down
Private Const WM_RBUTTONUP = &H205       'Button up
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim nid As NOTIFYICONDATA


Private Sub Form_Load()
'If the application dosen't have a previous instance then load the form
If App.PrevInstance = False Then
       nid.cbSize = Len(nid)
       nid.hwnd = Form1.hwnd
       nid.uId = vbNull
       nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
       nid.uCallBackMessage = WM_MOUSEMOVE
       nid.hIcon = Form1.Icon
       nid.szTip = "Double Click To Restore Your application.." & vbNullChar
       Shell_NotifyIcon NIM_ADD, nid
  End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Dim lMsg As Long
   Dim sFilter As String
   lMsg = X / Screen.TwipsPerPixelX
   Select Case lMsg
      Case WM_LBUTTONDOWN
      Case WM_LBUTTONUP
      Case WM_LBUTTONDBLCLK
      Form1.WindowState = vbMaximized
      Form1.Show
      Case WM_RBUTTONDOWN
      Case WM_RBUTTONUP
      Case WM_RBUTTONDBLCLK
   End Select
 End Sub
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid
End
End Sub
0
 
MennovdhCommented:
I had a nice class for that, at home though, I'll post it if I remember. I doubt I will though; it's almost weekend.
0
 
puranik_pCommented:
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
applayerCommented:
i have a nice small app i'm writing to notify you when you get some pop email that uses the systray.  it uses a bunch of systray code i found on the web...email mburke@applayer.com with a place to send it and i will.

...also do some google searches on frmSysTray and you may find some useful code.
0
 
vinnyd79Commented:
bobc, did you ever get an answer to your question?
0
 
GPrentice00Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept vinnyd79's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
 
GPrentice00Commented:
does as asked
0
All Courses

From novice to tech pro — start learning today.