Hey guys I have a system tray icon, but when I click on it I would like my menu that is already on my menu bar to show.


Dooes anyone know how to do thaT?

I tried to integrate this code into my project.,,


VB Code:
  1. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
  2. 'declaration for putting the application to system tray
  3. Private Type NOTIFYICONDATA
  4.     cbSize As Long
  5.     hwnd As Long
  6.     uId As Long
  7.     uFlags As Long
  8.     uCallBackMessage As Long
  9.     hIcon As Long
  10.     szTip As String * 64
  11. End Type
  12.  
  13.     'declare constants
  14. Private Const NIM_ADD = &H0
  15. Private Const NIM_MODIFY = &H1
  16. Private Const NIM_DELETE = &H2
  17. Private Const WM_MOUSEMOVE = &H200
  18. Private Const NIF_MESSAGE = &H1
  19. Private Const NIF_ICON = &H2
  20. Private Const NIF_TIP = &H4
  21.  
  22. 'The following constants are used to determine the mouse input on the
  23.  
  24.     'Left-click
  25. Private Const WM_LBUTTONDBLCLK = &H203   'Double click
  26. Private Const WM_LBUTTONDOWN = &H201     'down
  27. Private Const WM_LBUTTONUP = &H202       'up
  28.  
  29.     'Right-click
  30. Private Const WM_RBUTTONDBLCLK = &H206   'Double click
  31. Private Const WM_RBUTTONDOWN = &H204     'down
  32. Private Const WM_RBUTTONUP = &H205       'up
  33.  
  34. 'Dimension a variable as the user-defined data type.
  35. Dim nid As NOTIFYICONDATA
  36.  
  37.  
  38. Private Sub Ex_Click()
  39. Unload Me
  40. Shell_NotifyIcon NIM_DELETE, nid 'Delete the form's icon from the sys tray
  41. End Sub
  42. '   one main menu by Caption"Menu" name "TrayMenu"
  43. '   one sub menu by name caption "Exit" name "Ex"
  44. '   one sub menu by name caption "Show" name "Show"
  45.  
  46. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  47. Dim msg As Long
  48. Dim sFilter As String
  49. msg = X / Screen.TwipsPerPixelX
  50.     Select Case msg
  51.         Case WM_LBUTTONDOWN
  52.             MsgBox "you clicked me!"
  53.       Me.PopupMenu TrayMenu   'if u want u can call the popup menu
  54.         Case WM_LBUTTONUP
  55.         Case WM_LBUTTONDBLCLK
  56.         Case WM_RBUTTONDOWN
  57.         Case WM_RBUTTONUP
  58.             Me.PopupMenu TrayMenu  'call the popup menu
  59.         Case WM_RBUTTONDBLCLK
  60.     End Select
  61. End Sub
  62.  
  63.  
  64. Private Sub Form_Resize()
  65. If Me.WindowState = 1 Then
  66.  
  67.     Me.Hide
  68.     nid.cbSize = Len(nid)
  69.         nid.hwnd = Me.hwnd
  70.         nid.uId = vbNull
  71.         nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  72.         nid.uCallBackMessage = WM_MOUSEMOVE
  73.         nid.hIcon = Me.Icon
  74.         'u can give a tool tip text here
  75.         nid.szTip = "My System Tray Message" & vbNullChar
  76.        'Call the Shell_NotifyIcon function to add the icon to the System Tray, defulte form's icon
  77.  
  78.         Shell_NotifyIcon NIM_ADD, nid
  79.         Else
  80. End If
  81. End Sub
  82.  
  83. Private Sub Show_Click()
  84. Me.WindowState = 0
  85. Me.Show
  86. Shell_NotifyIcon NIM_DELETE, nid 'Delete the form's icon from the sys tray
  87. End Sub

so the icon will show up in my app, but no menu, and the menu is made.