dcsimg
Results 1 to 2 of 2

Thread: [VB6] Enhanced Tray Message w/ custom ToolTip icon and feedback, w/o ShellNotifyIcon

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,407

    [VB6] Enhanced Tray Message w/ custom ToolTip icon and feedback, w/o ShellNotifyIcon

    IUserNotification2 Interface

    IUserNotification provided a very simple way to show a notification in the tray area, but it was very limited in terms of interaction. Vista introduced IUserNotification2 with a progress sink that allows feedback when the balloon is clicked, when the icon is clicked, and when it's right clicked so a context menu can be displayed.

    (note that this is for a notification only, this is not suitable for a permanent presence in the tray)

    Once the support code is there, usage is very simple, with no subclassing required:

    Code:
    Dim lFlags As IUN_Flags
    
    Dim pNotice As UserNotification2
    Dim pQC As cQueryContinue
    Dim pNoticeCB As cUserNotificationCallback
    
    Set pNotice = New UserNotification2
    Set pQC = New cQueryContinue
    Set pNoticeCB = New cUserNotificationCallback
    
    'some code omitted here, just setting options, see sample project for full code
    
    With pNotice
        .SetBalloonInfo Text1.Text, Text2.Text, lFlags
        .SetIconInfo hIconS, Text4.Text
        If Text3.Text <> "" Then
            .PlaySound Text3.Text
        End If
        .SetBalloonRetry CLng(Text5.Text), CLng(Text6.Text), CLng(Text7.Text)
        
        .Show pQC, 500, pNoticeCB
    End With
    The sample project also shows how to display a menu when you right click the icon:

    Code:
    Public Function OnContextMenuVB(ByVal This As IUserNotificationCallback, pt As oleexp.POINT) As Long
    Form1.List1.AddItem "Context menu"
    Dim hMenu As Long
    Dim idCmd As Long
    hMenu = CreatePopupMenu()
    Call AppendMenu(hMenu, 0, 100, "Hide icon")
    Call AppendMenu(hMenu, 0, 101, "Leave icon alone")
    idCmd = TrackPopupMenu(hMenu, TPM_LEFTBUTTON Or TPM_RIGHTBUTTON Or TPM_LEFTALIGN Or TPM_TOPALIGN Or TPM_HORIZONTAL Or TPM_RETURNCMD, pt.X, pt.Y, 0, Form1.hWnd, 0)
    
    If idCmd = 100 Then OnContextMenuVB = 1
    
    End Function
    The only bit of complexity is that if you want to make use of the callback events, in order to set whether the icon stays or not requires swapping v-table entries. This would also be required to use IQueryContinue, but that's not shown since it's redundant.
    Theoretically, you could choose to not use either of these options by modifying the typelib to expect a pointer and passing 0, if you want a custom version of oleexp that does that let me know.

    IUserNotification2 does NOT inherit from IUserNotification, therefore both can be used simultaneously.

    Known Issues
    -Sound doesn't seem to work. MSDN says those aliases should be in win.ini and they're not in mine, but I didn't think a Vista+ interface would require something like that to be added.
    -You'll need an error handler... if you let it run through all retries, when it times out it throws a 'cancelled by user' automation error that will show unless you don't break on handled errors (and add the handler). This is not due to any code on this end, it's the system implementation that throws the error.

    Requirements:
    Vista or higher.
    oleexp 4.0 or higher (my Modern Interfaces Library expansion of olelib)
    Attached Files Attached Files

  2. #2
    New Member
    Join Date
    May 2015
    Location
    India
    Posts
    1

    Re: [VB6] Enhanced Tray Message w/ custom ToolTip icon and feedback, w/o ShellNotifyI

    Nice Work ..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width