Results 1 to 9 of 9

Thread: [RESOLVED] Minimize to SysTray bubble ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Resolved [RESOLVED] Minimize to SysTray bubble ?

    I am using the code found here, but I have a question
    TrayAdd hwnd, Me.Icon, "progress is at " &Variable or even a lable.caption, MouseMove

    I have used a variable (etc currentKey) and even a lables caption (etc lblMini.caption)

    This works when I minimize, but does not update as the caption changes or when variable changes, I have also tried to update with mousemove
    Case MouseMove
    Debug.Print "MouseMove"
    TrayAdd hwnd, Me.Icon, "Progress is " & lblMini.caption, MouseMove

    debug.print lblMini.caption

    It updates in the immediate window, but not the mouseover bubble,
    Is there a way to have this update?

    Code:
    '[Adding the tray]
    Private Sub cmdAdd_Click()
        TrayAdd hwnd, Me.Icon, "Progress is " & lblMini.caption, MouseMove
        mnuHide_Click
    debug.print lblMini.caption
    End Sub
    
    '[Checking The mouse event]
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim cEvent As Single
    cEvent = X / Screen.TwipsPerPixelX
    Select Case cEvent
        Case MouseMove
            Debug.Print "MouseMove"
        TrayAdd hwnd, Me.Icon, "Progress is " & lblMini.caption, MouseMove
        
        Case LeftUp
            Debug.Print "Left Up"
        Case LeftDown
            Debug.Print "LeftDown"
        Case LeftDbClick
            Debug.Print "LeftDbClick"
        Case MiddleUp
            Debug.Print "MiddleUp"
        Case MiddleDown
            Debug.Print "MiddleDown"
        Case MiddleDbClick
            Debug.Print "MiddleDbClick"
        Case RightUp
            Debug.Print "RightUp": PopupMenu mnuForm
        Case RightDown
            Debug.Print "RightDown"
        Case RightDbClick
            Debug.Print "RightDbClick"
    End Select
    End Sub

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Re: Minimize to SysTray bubble ?

    I reread my Original Post and I may not have been very clear (I even confused myself lol)

    Example I what I am trying to do;
    I am sure most everyone here has some sort of Adobe product.
    When Adobe Updater starts, it runs in system Tray, when it is downloading, and you mouseover it, it displays the % downloaded. Remouse over and it displays the updated % and so on.

    Thats basically what I want, just not a % but a value (of current or a lblMini.caption)

    It is not extremely critical, I can just remove this part, but it would be really nice to have.

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Minimize to SysTray bubble ?

    If you want to update the current trayicon make changes to its parameters then call Shell_NotifyIcon using the NIM_MODIFY flag.

    So if you want to update the tooltip text reset the .szTip parameter.... If your NOTIFYICONDATA was declared with the name TrayIcon it might look like this....

    TrayIcon.szTip = "Progress is " & lblMini.Caption & Chr$(0)
    Call Shell_NotifyIcon(NIM_MODIFY, TrayIcon)

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Re: Minimize to SysTray bubble ?

    Thanks, that makes a bit of sense to me.

    Though it seems I need to Dim trayIcon and nim_ADD

    Keep getting errors in trying to do so.

    The previous code is the complete form1 code, there is a Module as well that I will post, must be something I am overlooking however.

    Code:
    Option Explicit
    
    '[Tray Constants]
    Const NIF_MESSAGE    As Long = &H1     'Message
    Const NIF_ICON       As Long = &H2     'Icon
    Const NIF_TIP        As Long = &H4     'TooTipText
    Const NIM_ADD        As Long = &H0     'Add to tray
    Const NIM_MODIFY     As Long = &H1     'Modify
    Const NIM_DELETE     As Long = &H2     'Delete From Tray
    
    '[Type NotifyIconData For Tray Icon]
    Private Type NOTIFYICONDATA
        cbSize As Long
        hwnd As Long
        uId As Long
        uFlags As Long
        uCallBackMessage As Long
        hIcon As Long
        szTip As String * 64
    End Type
    
    '[Return Events]
    Public Enum TrayRetunEventEnum
        MouseMove = &H200       'On Mousemove
        LeftUp = &H202          'Left Button Mouse Up
        LeftDown = &H201        'Left Button MouseDown
        LeftDbClick = &H203     'Left Button Double Click
        RightUp = &H205         'Right Button Up
        RightDown = &H204       'Right Button Down
        RightDbClick = &H206    'Right Button Double Click
        MiddleUp = &H208        'Middle Button Up
        MiddleDown = &H207      'Middle Button Down
        MiddleDbClick = &H209   'Middle Button Double Click
    End Enum
    
    '[Modify Items]
    Public Enum ModifyItemEnum
        ToolTip = 1             'Modify ToolTip
        Icon = 2                'Modify Icon
    End Enum
    
    '[API]
    Private TrayIcon As NOTIFYICONDATA
    Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    
    '[Add to Tray]
    Public Sub TrayAdd(hwnd As Long, Icon As Picture, _
                        ToolTip As String, ReturnCallEvent As TrayRetunEventEnum)
        With TrayIcon
            .cbSize = Len(TrayIcon)
            .hwnd = hwnd
            .uId = vbNull
            .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
            .uCallBackMessage = ReturnCallEvent
            .hIcon = Icon
            .szTip = ToolTip & vbNullChar
        End With
        Shell_NotifyIcon NIM_ADD, TrayIcon
    End Sub
    
    '[Remove From tray]
    Public Sub TrayDelete()
        Shell_NotifyIcon NIM_DELETE, TrayIcon
    End Sub
    
    '[Modify the tray]
    Public Sub TrayModify(Item As ModifyItemEnum, vNewValue As Variant)
        Select Case Item
            Case ToolTip
                TrayIcon.szTip = vNewValue & vbNullChar
            Case Icon
                TrayIcon.hIcon = vNewValue
        End Select
        Shell_NotifyIcon NIM_MODIFY, TrayIcon
    End Sub
    I added
    Const NIM_ADD As Long = &H0 'Add to tray
    to my form1 but then I need to dim TrayIcon?

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Minimize to SysTray bubble ?

    You only want to Add the tray icon once, then use modify to update it..


    something like...

    Code:
    Private Sub Form_Load()
     TrayAdd Me.hwnd, Me.Icon, "My program v1.0", MouseMove
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        
        Dim cEvent As Single
        cEvent = X / Screen.TwipsPerPixelX
        
        Select Case cEvent
            Case MouseMove
              TrayModify ToolTip, "Progress is " & lblMini.Caption
        End Select
    
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        TrayDelete
    End Sub

    EDIT BTW, it's actually better to use a hidden picture box for the tray icon handle and detect the mouse move events there instead of the form, it's been discussed here many times, otherwise you can run into some weird issues like the form moving when the user clicks on the tray icon and then moves the mouse, etc. Plus if you set the pic box to pixel scalemode you can then just use it' X position for the select case.
    Last edited by Edgemeal; Feb 8th, 2010 at 09:16 PM.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Re: Minimize to SysTray bubble ?

    Select Case cEvent
    Case MouseMove
    TrayModify ToolTip, "Progress is " & lblMini.Caption
    End Select
    This what worked.
    TY TY TY!!!!

    EDIT:
    Your edit has confused me lol.

    I will reread and try to digest it.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Re: Minimize to SysTray bubble ?

    The tray icon is only added when form is hidden, does that matter? or am I still going to run into issues?

    Thanx.

    BTW, your post is Rated, thank you again.

  8. #8
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Minimize to SysTray bubble ?

    You might consider playing around with the SysTray demo project linked in my signature. It has an example of the picturebox technique Edgemeal is talking about. (He helped me write it.)

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Re: Minimize to SysTray bubble ?

    Thanx, I will take a look and mess around with it.

    Thanx again!

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