Results 1 to 5 of 5

Thread: System Tray Icon Question

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    System Tray Icon Question

    How can I put a different icon in the system tray other than the one assigned to my programs form? I want to be able to change the icon in the system tray durring different parts of my program.. depending on what it is doing (ie. running.. idle) i tried setting .icon property of the NOTIFYICONDATA data type to LoadPicture(iconfile) i get no error but it does not work...

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    See code line in Red.
    VB Code:
    1. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    2.  
    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. Private Const NIM_ADD = &H0
    14. Private Const NIM_MODIFY = &H1
    15. Private Const NIM_DELETE = &H2
    16. Private Const WM_MOUSEMOVE = &H200
    17. Private Const NIF_MESSAGE = &H1
    18. Private Const NIF_ICON = &H2
    19. Private Const NIF_TIP = &H4
    20. Private Const WM_LBUTTONDBLCLK = &H203
    21. Private Const WM_LBUTTONDOWN = &H201
    22. Private Const WM_LBUTTONUP = &H202
    23. Private Const WM_RBUTTONDBLCLK = &H206
    24. Private Const WM_RBUTTONDOWN = &H204
    25. Private Const WM_RBUTTONUP = &H205
    26.  
    27. Private SysTray As NOTIFYICONDATA
    28.  
    29. Private Sub StartInSysTray()
    30.     SysTray.cbSize = Len(SysTray)
    31.     SysTray.hwnd = Picture1.hwnd
    32.     SysTray.uId = 1&
    33.     SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    34.     SysTray.ucallbackMessage = WM_MOUSEMOVE
    35.     'change the below line to the desired icon
    36.     [COLOR=red]SysTray.hIcon = Me.Icon[/COLOR]
    37.     SysTray.szTip = "&R&e&s&t&a&r&t" & Chr$(0)
    38.     Shell_NotifyIcon NIM_ADD, SysTray
    39.     Me.Hide
    40.     App.TaskVisible = False
    41. End Sub
    42.  
    43. Private Sub Form_Load()
    44. StartInSysTray
    45. End Sub
    46.  
    47. Private Sub Form_Unload(Cancel As Integer)
    48.     SysTray.cbSize = Len(SysTray)
    49.     SysTray.hwnd = Picture1.hwnd
    50.     SysTray.uId = 1&
    51.     Shell_NotifyIcon NIM_DELETE, SysTray
    52. End Sub
    53.  
    54. 'Add A Picture Control To The Form.   Set its visible property to False
    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.    
    67.     Case WM_LBUTTONDBLCLK
    68.          
    69.     Case WM_LBUTTONUP
    70.          
    71.     Case WM_RBUTTONUP
    72.          
    73.     End Select
    74.         rec = False
    75.     End If
    76.  
    77. End Sub

  3. #3
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    I know this probably isn't what you want, but why not just change the icon of the form whenever you want it to change?

    --EDIT--

    yeah... what Hack said... damn he's quick.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Hack,
    The problem that I was having is that I wanted to Load the icon from a file and the LoadPicture method wasn't doing it.. but I came up with another solution anyway since I have a status bar that has the icons I need in it.. i just referenced the panel(x).picture property and loaded that icon into the system tray over the old one... is there a way I can make an icon blink at a certain time in the systray? I am creating a crystal reports scheduler and I want it to blink while the reports are running

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Right off the top of my head, I'd say use two buttons, one with the icon, one without. Set a timer to toggle their visible property but there is probably a better way. I'm taking a half day, so I'm outta here.

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