Results 1 to 4 of 4

Thread: Systray icon not working properly [SOLVED]

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Systray icon not working properly [SOLVED]

    I have my code as defined here.

    The icon shows in the system tray ok, but when I try to doubleclick the icon, the Picture1_DblClick event doesn't fire.
    Last edited by hothead; May 9th, 2004 at 07:32 AM.

  2. #2
    Lively Member rotcrules's Avatar
    Join Date
    Mar 2004
    Location
    SD
    Posts
    113
    here try this:
    VB Code:
    1. 'Puts app icon in the system tray
    2. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    3.  
    4. Private Type NOTIFYICONDATA
    5.     cbSize As Long
    6.     hWnd As Long
    7.     uId As Long
    8.     uFlags As Long
    9.     ucallbackMessage As Long
    10.     hIcon As Long
    11.     szTip As String * 64
    12. End Type
    13.  
    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. Private Const WM_LBUTTONDBLCLK = &H203
    22. Private Const WM_LBUTTONDOWN = &H201
    23. Private Const WM_LBUTTONUP = &H202
    24. Private Const WM_RBUTTONDBLCLK = &H206
    25. Private Const WM_RBUTTONDOWN = &H204
    26. Private Const WM_RBUTTONUP = &H205
    27.  
    28. Private SysTray As NOTIFYICONDATA
    29. Dim Result As Long
    30. Private Sub StartInSysTray()
    31.     SysTray.cbSize = Len(SysTray)
    32.     SysTray.hWnd = Picture1.hWnd
    33.     SysTray.uId = 1&
    34.     SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    35.     SysTray.ucallbackMessage = WM_MOUSEMOVE
    36.     'change the below line to the desired icon
    37.     SysTray.hIcon = Me.Icon
    38.     SysTray.szTip = App.EXEName & ".exe"
    39.     Shell_NotifyIcon NIM_ADD, SysTray
    40.     Me.Hide
    41. End Sub
    42.  
    43. Private Sub Form_Load()
    44. StartInSysTray
    45. End Sub
    46.  
    47. Private Sub Form_Unload(Cancel As Integer)
    48.     'Remove the icon from the system tray
    49.     SysTray.cbSize = Len(SysTray)
    50.     SysTray.hWnd = Picture1.hWnd
    51.     SysTray.uId = 1&
    52.     Shell_NotifyIcon NIM_DELETE, SysTray
    53. End Sub
    54.  
    55. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
    56.  
    57. Static rec As Boolean, msg As Long
    58.     Dim RetVal As String
    59.     Dim returnstring
    60.     Dim retvalue
    61.     msg = x / Screen.TwipsPerPixelX
    62.     If rec = False Then
    63.         rec = True
    64.     Select Case msg
    65.     Case WM_LBUTTONDOWN
    66.         Me.Show
    67.         Me.WindowState = vbNormal
    68.    
    69.     Case WM_LBUTTONUP
    70.          
    71.     Case WM_RBUTTONblck
    72. 'Bring up the menu if the right mouse button is clicked over the icon
    73. 'what is this for?
    74. If Button = vbRightButton Then
    75. PopupMenu me.mnuFile
    76. End If
    77. '
    78.     Case WM_RBUTTONUP
    79.  
    80.     End Select
    81.         rec = False
    82.     End If
    83.  
    84. End Sub

    does that work?
    Last edited by rotcrules; May 8th, 2004 at 10:31 PM.

  3. #3
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236
    The icon shows in the system tray ok, but when I try to doubleclick the icon, the Picture1_DblClick event doesn't fire.

    Thats because your using Picture1_DblClick not Form_DblClick. The picture in the systray isn't a picture on a Form, its the Form Icon.

    There are loads of examples of using systray on here, do a search for "systray"

    Here is a systray I posted.

    http://www.vbforums.com/showthread.php?threadid=288456&

  4. #4

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Originally posted by rotcrules
    here try this:
    VB Code:
    1. 'Puts app icon in the system tray
    2. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    3.  
    4. Private Type NOTIFYICONDATA
    5.     cbSize As Long
    6.     hWnd As Long
    7.     uId As Long
    8.     uFlags As Long
    9.     ucallbackMessage As Long
    10.     hIcon As Long
    11.     szTip As String * 64
    12. End Type
    13.  
    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. Private Const WM_LBUTTONDBLCLK = &H203
    22. Private Const WM_LBUTTONDOWN = &H201
    23. Private Const WM_LBUTTONUP = &H202
    24. Private Const WM_RBUTTONDBLCLK = &H206
    25. Private Const WM_RBUTTONDOWN = &H204
    26. Private Const WM_RBUTTONUP = &H205
    27.  
    28. Private SysTray As NOTIFYICONDATA
    29. Dim Result As Long
    30. Private Sub StartInSysTray()
    31.     SysTray.cbSize = Len(SysTray)
    32.     SysTray.hWnd = Picture1.hWnd
    33.     SysTray.uId = 1&
    34.     SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    35.     SysTray.ucallbackMessage = WM_MOUSEMOVE
    36.     'change the below line to the desired icon
    37.     SysTray.hIcon = Me.Icon
    38.     SysTray.szTip = App.EXEName & ".exe"
    39.     Shell_NotifyIcon NIM_ADD, SysTray
    40.     Me.Hide
    41. End Sub
    42.  
    43. Private Sub Form_Load()
    44. StartInSysTray
    45. End Sub
    46.  
    47. Private Sub Form_Unload(Cancel As Integer)
    48.     'Remove the icon from the system tray
    49.     SysTray.cbSize = Len(SysTray)
    50.     SysTray.hWnd = Picture1.hWnd
    51.     SysTray.uId = 1&
    52.     Shell_NotifyIcon NIM_DELETE, SysTray
    53. End Sub
    54.  
    55. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
    56.  
    57. Static rec As Boolean, msg As Long
    58.     Dim RetVal As String
    59.     Dim returnstring
    60.     Dim retvalue
    61.     msg = x / Screen.TwipsPerPixelX
    62.     If rec = False Then
    63.         rec = True
    64.     Select Case msg
    65.     Case WM_LBUTTONDOWN
    66.         Me.Show
    67.         Me.WindowState = vbNormal
    68.    
    69.     Case WM_LBUTTONUP
    70.          
    71.     Case WM_RBUTTONblck
    72. 'Bring up the menu if the right mouse button is clicked over the icon
    73. 'what is this for?
    74. If Button = vbRightButton Then
    75. PopupMenu me.mnuFile
    76. End If
    77. '
    78.     Case WM_RBUTTONUP
    79.  
    80.     End Select
    81.         rec = False
    82.     End If
    83.  
    84. End Sub

    does that work?
    Yes, this works. Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width