Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

[VB6] Yet another simple and versatile Tray Icon code with subclassing

$
0
0
Yesterday, I didn't know what 'subclassing' is.
Today I made a complete solution to serve all your tray icon needs.

Easy to use: just create a cSysTray object in your form, pass the hWnd and you're set.
You can add and remove icons at will, change tooltips, create baloons and catch events from every icon.
Unfortunately the code needs 3 files, 2 class files and a module to do all the subclassing stuff, but it's very easy to use.
I grabbed some code from this post by Ellis Dee, hence the wrench icon on the form. And included some ideas from this post on subclassing by fafalone.

There are 2 BAS files on the zip:
modSysTray.bas uses SetWindowSubclass, RemoveWindowSubclass, DefSubclassProc
modSysTray_old.bas uses SetWindowLong, CallWindowProc
You can use any of them but the 1st one is better.


The code is not finished yet. It works perfectly on windows xp and win 7, but there are a lot of things to include like add other events, add support for baloon alternative icons, msn style baloons, and some other minor changes.
Note that I didn't include any routine to create icons from bitmaps or anything else. You need a 16x16 ICON picture. No mask creation, no scaling, no nothing.

Here's a screenshot:
Name:  pic.jpg
Views: 55
Size:  16.4 KB

And a minimal form code sample:
Code:

Option Explicit
Private WithEvents sysTray As cSysTray

Private Sub Form_Load()
    Set sysTray = New cSysTray
    sysTray.Init Me.hWnd
    sysTray.AddIcon (pic.Picture, "Hola mundo").ShowBalloon "my baloon", "baloon title", NIIF_NOSOUND Or NIIF_ERROR
    sysTray.AddIcon Me.Icon, "Hola mundo 2"
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set sysTray = Nothing
End Sub

Private Sub sysTray_DoubleClick(index As Integer)
    Debug.Print "dblclick"; index
End Sub

Private Sub sysTray_RightClick(index As Integer)
    Debug.Print "rtclick"; index
End Sub

Attached Images
 
Attached Files

Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>