Re: Looking for good systray code



"nop90" <bjones_calif@xxxxxxxxx> wrote in message
news:Xns981E58DADA145bjonescalif@xxxxxxxxxxxxxxxxx
Please help me find good systray code. I must have looked/tried 20
different versions of systray code and they dont do what I want or have
some kind of problem. The one I am using now is working except the code
grabs focus from other apps. Not a good thing (got it from Planet Source
Code).

What I need is the following...
* ability to change the systray icon color.
* ability to change the systray icon text.

I have used the following code with reliable results:

http://vbnet.mvps.org/code/subclass/shellnotifybasic.htm

There is a link to other samples, one of which is for animating the tray
icon. To modify the icon and the tool tip text, I added the following code,
which takes as parameters a PictureBox that contains a new version of the
icon, and the new tool tip text:

' Returns True when successful
Public Function ModifyTrayIcon(ByRef pct As PictureBox, ByRef IconText As
String) As Boolean
On Error GoTo ErrorHandler

If NOTIFYICONDATA_SIZE = 0 Then SetShellVersion

With NID
.cbSize = NOTIFYICONDATA_SIZE
.hWnd = Form1.hWnd
.uID = 125&
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MYHOOK
.hIcon = pct.Picture
' Limit the icon text to what the API can handle
.szTip = Left(IconText, 63) & Chr(0)
End With

ModifyTrayIcon = CBool(Shell_NotifyIcon(NIM_MODIFY, NID))

ExitMe:
Exit Function
ErrorHandler:
MsgBox "ModifyTrayIcon: Error " & Err.Number & ": " & Err.Description
Resume ExitMe
End Function

I never needed to draw on the PictureBox, then make it appear on the tray
icon, but you could try it. You may have to use Picture1.Refresh before
calling the routine above. Try the following untested code to draw on the
icon, for example:

Picture1.ScaleMode = vbPixels
Picture1.Circle (7, 7), 5, QBColor(vbMagenta)
Picture1.Refresh
Debug.Print "ModifyTrayIcon: " & ModifyTrayIcon(Picture1, "New Icon Text")


* have a systray icon menu.

The sample above shows you how.

* dont want the application to grab focus from another app when the app is
running in the systray.

That's the most difficult requirement. Because the user will have a problem
dismissing the menu if your app is not on the foreground, however, you could
try making a second form, Form2, with None border style and width and height
of 0. I am not sure if that will work. Save your work before each run
because you will most likely crash the IDE until you get it to work.

* ability to close the app from the systray menu.

Covered in the sample above.

* have a tool tip and change the tooltip text.

See my routine above.




.



Relevant Pages

  • Re: Is it possible to remove 3rd party app icon from systray?
    ... that creates chaos in the systray. ... close the icon, ... My app starts the 3rd party app using runas, ... for command line options your 3rd party app might support. ...
    (microsoft.public.vb.general.discussion)
  • Re: repeat something in a thread, but stop when the program stops
    ... > very tiny amount of work every half a second, ... For example, if a program puts an icon in the Windows systray, then it ... Apps in the systray often do a lot more than just that too. ... A Python thread waking up to see whether a Python Queue has something ...
    (comp.lang.python)
  • Re: Moving MsgBox
    ... started building a systray in my project using a DLL from the ... of/and OCX's is for placing an icon in the Systray, ... vertical bar graph's in their system tray icon to show UL & DL activity, ...
    (microsoft.public.vb.general.discussion)
  • Re: Some Systray icons disapear after explorer crash
    ... >> Some of my systray icons dissapear after the explorer ... >> explorer crashed, how would you get these icons to stay when explorer ... > when the app starts, it places it's icon in the system tray by telling ...
    (microsoft.public.windowsxp.general)
  • Re: Volume Control does not stay in Sys Tray
    ... SNDVOL32.exe from appearing in the SYSTRAY. ... > Troubleshooting the Volume Control Icon ... > Volume Icon Is Displayed Incorrectly in the Notification Area After the ...
    (microsoft.public.windowsxp.general)