Re: Looking for good systray code
- From: "expvb" <nobody@xxxxxxx>
- Date: Mon, 14 Aug 2006 06:35:07 -0400
"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.
.
- References:
- Looking for good systray code
- From: nop90
- Looking for good systray code
- Prev by Date: Re: How to make the program copy itself to the local drive and open that file, then close itself?
- Next by Date: Re: Proper declaration and population of an array
- Previous by thread: Re: Looking for good systray code
- Next by thread: Frage zu AlphaBlend
- Index(es):
Relevant Pages
|