Results 1 to 2 of 2

Thread: mouse down on system tray icon, not notify icon

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Location
    Porto Alegre, RS
    Posts
    210

    mouse down on system tray icon, not notify icon

    i am using this:

    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Module api
    4.  
    5.     Public Result As Boolean
    6.     <StructLayout(LayoutKind.Sequential)> Public Structure NOTIFYICONDATA
    7.         Dim cbSize As Int32
    8.         Dim hwnd As IntPtr
    9.         Dim uID As Int32
    10.         Dim uFlags As Int32
    11.         Dim uCallbackMessage As IntPtr
    12.         Dim hIcon As IntPtr
    13.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Dim szTip As String
    14.         Dim dwState As Int32
    15.         Dim dwStateMask As Int32
    16.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Dim szInfo As String
    17.         Dim uVersion As Int32
    18.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Dim szInfoTitle As String
    19.         Dim dwInfoFlags As Int32
    20.     End Structure
    21.  
    22.     Public Const NIF_MESSAGE As Int32 = &H1
    23.     Public Const NIF_ICON As Int32 = &H2
    24.     Public Const NIF_STATE As Int32 = &H8
    25.     Public Const NIF_INFO As Int32 = &H10
    26.     Public Const NIF_TIP As Int32 = &H4
    27.     Public Const NIM_ADD As Int32 = &H0
    28.     Public Const NIM_MODIFY As Int32 = &H1
    29.     Public Const NIM_DELETE As Int32 = &H2
    30.     Public Const NIM_SETVERSION As Int32 = &H4
    31.     Public Const NOTIFYICON_VERSION As Int32 = &H5
    32.     Public Const NIS_HIDDEN = &H1
    33.     Public Const NIS_SHAREDICON = &H2
    34.     Public Const NIIF_ERROR = &H3
    35.     Public Const NIIF_INFO = &H1
    36.     Public Const NIIF_NONE = &H0
    37.     Public Const NIIF_WARNING = &H2
    38.     Public Const NIM_SETFOCUS = &H4
    39.     Public Const NIIF_GUID = &H5
    40.     Public Declare Function Shell_NotifyIcon Lib "shell32.dll" _
    41.     Alias "Shell_NotifyIconA" (ByVal dwMessage As Int32, _
    42.     ByRef lpData As NOTIFYICONDATA) As Boolean
    43.     Public uNIF As NOTIFYICONDATA
    44.  
    45.     ' Displays a balloon info notification
    46.  
    47.     Public Sub SendBalloonInfoNotification(ByVal strInfo As String)
    48.         With uNIF
    49.             .uFlags = NIF_INFO
    50.             .uVersion = 2000
    51.             .szInfoTitle = "Info"
    52.             .szInfo = strInfo
    53.             .dwInfoFlags = NIIF_INFO
    54.         End With
    55.         Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)
    56.     End Sub
    57.  
    58.     ' Displays a balloon warning notification
    59.  
    60.     Public Sub SendBalloonWarningNotification(ByVal strWarning As String)
    61.         With uNIF
    62.             .uFlags = NIF_INFO
    63.             .uVersion = 2000
    64.             .szInfoTitle = "Warning"
    65.             .szInfo = strWarning
    66.             .dwInfoFlags = NIIF_WARNING
    67.         End With
    68.         Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)
    69.     End Sub
    70.  
    71.     ' Displays a balloon error notification
    72.  
    73.     Public Sub SendBalloonErrorNotification(ByVal strError As String)
    74.         With uNIF
    75.             .uFlags = NIF_INFO
    76.             .uVersion = 2000
    77.             .szInfoTitle = "Error"
    78.             .szInfo = strError
    79.             .dwInfoFlags = NIIF_ERROR
    80.         End With
    81.         Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)
    82.     End Sub
    83.  
    84.     ' Removes the application icon from the system tray
    85.  
    86.     Public Sub RemoveIconFromTray(ByRef frmForm As System.Windows.Forms.Form)
    87.         With uNIF
    88.             .cbSize = Marshal.SizeOf(uNIF)
    89.             .hwnd = frmForm.Handle()
    90.             .uID = 1
    91.         End With
    92.         Shell_NotifyIcon(NIM_DELETE, uNIF)
    93.     End Sub
    94.     ' Adds a application icon to system tray
    95.  
    96.     Public Sub AddIconToTray(ByRef frmForm As System.Windows.Forms.Form)
    97.         With uNIF
    98.             .cbSize = Marshal.SizeOf(uNIF)
    99.             .hwnd = frmForm.Handle
    100.             .uID = 1
    101.             .uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
    102.             .uCallbackMessage = New IntPtr(&H500)
    103.             .uVersion = NOTIFYICON_VERSION
    104.             .hIcon = frmForm.Icon.Handle
    105.         End With
    106.         Result = Shell_NotifyIcon(NIM_ADD, uNIF)
    107.     End Sub
    108.  
    109. End Module

    to display an icon on the system tray, on the load event i call:
    VB Code:
    1. AddIconToTray(Me)

    how can i get the mouse events of the icon that goes to the system tray?


    Thank you,
    Guilherme Costa

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Why aren't you using the NotifyIcon control? That makes life a lot easier. Otherwise rumage through VB6 code that uses the APIs and see how it captured the mouse click.

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