Results 1 to 1 of 1

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

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    7

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

    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: 1698
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 Files Attached Files

Tags for this Thread

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