Results 1 to 7 of 7

Thread: system tray icons\minimizing forms

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506

    system tray icons\minimizing forms

    don't slate me just yet, im not asking how to put an icon in the system tray.
    but.. ive noticed on some programs when they are 'minimized to the system tray' the actual minimize animation points to your system tray; towards the far right of your taskbar instead of where the applications icon button resides on the taskbar. if your lost and have msn, try closing it (so it goes to the system tray) and you'll see what i mean
    anyway more to the point, i was wondering how you'd achieve this in vb? im guessing its with api or is it much simpler?
    -cheers

  2. #2
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    do you mean when you would click the close button on a program like kasaa

  3. #3
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    put the following in a module

    VB Code:
    1. 'Puts app icon in the system tray
    2. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    3.  
    4. Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
    5. Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    6. Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    7.  
    8.  
    9. Private Type NOTIFYICONDATA
    10.     cbSize As Long
    11.     hWnd As Long
    12.     uId As Long
    13.     uFlags As Long
    14.     ucallbackMessage As Long
    15.     hIcon As Long
    16.     szTip As String * 17
    17. End Type
    18.  
    19.  
    20. Private Const NIM_ADD = &H0
    21. Private Const NIM_MODIFY = &H1
    22. Private Const NIM_DELETE = &H2
    23. Private Const WM_MOUSEMOVE = &H200
    24. Private Const NIF_MESSAGE = &H1
    25. Private Const NIF_ICON = &H2
    26. Private Const NIF_TIP = &H4
    27. Private Const WM_LBUTTONDOWN = &H201
    28. Private Const WM_RBUTTONDBLCLK = &H206
    29. Private Const WM_RBUTTONDOWN = &H204
    30.  
    31. Public Const WM_RBUTTONUP = &H205
    32. Public Const WM_LBUTTONUP = &H202
    33. Public Const SM_CXBORDER = 5    'Width of non-sizable borders
    34. Public Const SM_CYBORDER = 6    'Height of non-sizable borders
    35.  
    36.  
    37. Private SysTray As NOTIFYICONDATA
    38.  
    39. Public Sub StartInSysTray(f As Form)
    40.     SysTray.cbSize = Len(SysTray)
    41.     SysTray.hWnd = f.Picture1.hWnd
    42.     SysTray.uId = 1&
    43.     SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    44.     SysTray.ucallbackMessage = WM_MOUSEMOVE
    45.     'change the below line to the desired icon
    46.     SysTray.hIcon = f.Icon
    47.     SysTray.szTip = Left$(App.Title, Len(App.Title))
    48.     Shell_NotifyIcon NIM_ADD, SysTray
    49. End Sub
    50.  
    51. Public Sub RemoveFromSysTray(f As Form)
    52.     'Remove the icon from the system tray
    53.     SysTray.cbSize = Len(SysTray)
    54.     SysTray.hWnd = f.Picture1.hWnd
    55.     SysTray.uId = 1&
    56.     Shell_NotifyIcon NIM_DELETE, SysTray
    57. End Sub


    put the following in the form

    VB Code:
    1. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     Dim lRet As Long
    3.     Dim lBut As Long
    4.     Dim i As Integer
    5.    
    6.     'Get position of pointer.
    7.     lBut = x / Screen.TwipsPerPixelX
    8.    
    9.    
    10.     'Determine which mouse button clicked.
    11.     If lBut = WM_RBUTTONUP Then
    12.         'If right button determine if the app is visible.
    13.         If Me.Visible Then
    14.             'If the app is visible hide the restore option
    15.             With mnuFileSub
    16.                 For i = .LBound To .UBound
    17.                     If .Item(i).Caption = "&Restore" Then
    18.                         .Item(i).Visible = False
    19.                     Else
    20.                         .Item(i).Visible = True
    21.                     End If
    22.                 Next i
    23.             End With
    24.         Else
    25.             'If the app isn't visible show the restore option.
    26.             With mnuFileSub
    27.                 For i = .LBound To .UBound
    28.                     Select Case .Item(i).Caption
    29.                         Case "&Restore"
    30.                             .Item(i).Visible = True
    31.                         Case "&Quit"
    32.                             .Item(i).Visible = True
    33.                         Case "&About"
    34.                             .Item(i).Visible = True
    35.                     End Select
    36.                 Next i
    37.             End With
    38.         End If
    39.         'Following API call is used for it mouse pointer is not
    40.         'over the icon in the system tray and the popup menu is
    41.         'displayed so that it will be hidden if the pointer is
    42.         'clicked anywhere else.
    43.         lRet = SetForegroundWindow(Me.hWnd)
    44.        
    45.         'Display the popup menu for restoring or
    46.         'ending the app.
    47.         PopupMenu mnuFile
    48.     ElseIf lBut = WM_LBUTTONUP Then
    49.         'If a singl left mouse button click restore
    50.         'the app.
    51.         Call mnuFileSub_Click(1)
    52.     End If
    53. End Sub
    54.  
    55. Private Sub Form_Unload(Cancel As Integer)
    56.     'Set to one so form can't close until bClose is True.
    57.     Cancel = 1
    58.    
    59.     If bClose Then
    60.         'Remove the icon from the system tray.
    61.         Call RemoveFromSysTray(Me)
    62.         'Set to zero to end the app.
    63.         Cancel = 0
    64.         'Re-allocate memory.
    65.         Set frmRefresher = Nothing
    66.     Else
    67.         Me.WindowState = vbMinimized
    68.         DoEvents
    69.         'If the close button (X) is pressed.
    70.         Me.Hide
    71.         bClose = False
    72.         Exit Sub
    73.     End If
    74. End Sub
    75.  
    76.  
    77. Private Sub Form_Load()
    78.     'Put icon in system tray.
    79.     Call StartInSysTray(Me)
    80. End Sub

    hope this helps

  4. #4
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    if you would like you can go to this thread i made two days ago and download that code and program that is there and take a look at to get an ideahttp://www.vbforums.com/showthread.p...hreadid=245058

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    cheers m8, but ive already got an icon in the system tray.
    its when you minimize a window the menubar of the window actually floats down to the taskbar and on some programs it floats down towards the far right of the taskbar > over the system tray. i dont think you know what i mean lol, tis hard to explain

  6. #6
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Lightbulb Well

    I think i got what u mean.
    Well, what you're trying to do cannot be done in VB. I mean you cannot point the minimize animation to the tray. On the other hand, this is what you can do:

    In the tray code, you'll find somewhere something like:

    form1.WindowState = vbMinimized
    form1.Hide or form1.Visible = False

    Then elsewhere:

    form1.Show or form1.Visible = True
    form1.WindowState = vbNormal or vbMaximized.

    Try removing the the (form1.WindowState = vbMinimized) and the (form1.WindowState = vbNormal or vbMaximized) statements.
    This may sometimes cause a focus problem with the form. If so, use this code when showing it out of the tray:
    form1.Show
    form1.SetFocus

    Well, this is what i do when i don't want animation into the taskbar. It's the minimze action that's casuing it.
    And by the way, as far as MSN, i think they're using the same approach, because i didn't notice any animation at all (this is what the code i proposed do, it cancels the animation part).

    HTH
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  7. #7
    Member
    Join Date
    Sep 2001
    Location
    Jamaica
    Posts
    35
    Virus, in your vb code, in the Form_Unload event, when is bClose set to True? Or is it never gonna be set to true?

    And is calling the DoEvents() function really needeD?

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