Results 1 to 9 of 9

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
    5,651

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

    IUserNotification2 Interface
    Name:  IUserNotification.jpg
Views: 1219
Size:  51.9 KB

    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
    Last edited by fafalone; Dec 14th, 2020 at 03:55 PM. Reason: Attached project updated to reference oleexp.tlb 4.0 or higher

  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 ..

  3. #3
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

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

    Hi, when I try to run the attached project it complains about ""Missing reference: Fafalone's olelib Expantion v1.7". I downloaded your latest oleexp.tlb but apparently VB6 didn't like that one, maybe because it's v4.62? Indeed, VB doesn't want to load the reference from that folder anyhow. Only when I copy oleexp.tlb into SysWow64 I'm able to register the file in the reference dialog. However, when running the project I get an error "Compile error: Ambiguous name detected: NIIF_USER and when I open the object browser I can see the library contains 2 instances of NIIF_USER, and several others. I understand this is an old project while the library have had quite a few updates since the original post, but would appreciate if you had a look at it.

    Apparently,
    Code:
    Dim lFlags As IUN_Flags
    isn't enough, but when I change th eline triggering the error from
    Code:
    lFlags = NIIF_USER
    to
    Code:
    lFlags = IUN_Flags.NIIF_USER
    that clears the error, but then comes the next of course, but that shouldn't really be needed. Any ideas?
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

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

    I went back and changed all the old demos when I changed the identifier on TLB, but I guess this one slipped through the cracks.

    At some point it seems an NII_Flags enum got added to the TLB that duplicates the entries of IUN_Flags, and I would have thought that would raise an error compiling the TLB, so hadn't thoroughly checked for such a thing, but apparently not.

    I've updated the attached project to reference the newer TLB version, and the code to explicitly state IUN_Flags. on all of them, but I'll need some time to update the TLB to remove the need to explicitly specify (for this instance only, this isn't a common issue with enums). The new download will work now with those changes though.

  5. #5
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

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

    Thanks for fast reply and handling it, but... it seems like the project download disappeared somehow ;-)
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

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

    Tried again... have had a few problems with attachments here lately.

    If for some reason it's gone again, the duplicate variables are fixed like you already figured out, there's no more outside the NIIF_ ones in that block of code. And the reference, just uncheck the reference to 1.7 and add a new reference to 4.62.

  7. #7
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

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

    Yes that fixed the errors, however, when running the project and click the show button, nothing seems to happen. I haven't had time yet to investigate closer.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

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

    I just checked on both Windows 7 and Windows 10, the demo worked on both for me, so will definitely need to get some more detailed info.

  9. #9
    Addicted Member
    Join Date
    Jun 2010
    Posts
    182

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

    Hi, I'll have to come back to this later as other tasks are calling for priority right now. Thanks for your assistance and for the type library, which I need to set aside time to do a deeper study on, over the holidays maybe. Your contribution is highly appreciated.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

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