Results 1 to 11 of 11

Thread: Minimizing to the Systay

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    152

    Exclamation Minimizing to the Systay

    i want my program to be running all the time, but be minimized to the SysTray, does anyone know how do do that, and open it when it is double clicked? thanks in advance

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    VB Code:
    1. Private Type NOTIFYICONDATA
    2.     cbSize As Long
    3.     hWnd As Long
    4.     uId As Long
    5.     uFlags As Long
    6.     ucallbackMessage As Long
    7.     hIcon As Long
    8.     szTip As String * 64
    9. End Type
    10.  
    11. Private Const NIM_ADD = &H0
    12. Private Const NIM_MODIFY = &H1
    13. Private Const NIM_DELETE = &H2
    14. Private Const NIF_MESSAGE = &H1
    15. Private Const NIF_ICON = &H2
    16. Private Const NIF_TIP = &H4
    17.  
    18. Private Const WM_LBUTTONDBLCLK = &H203
    19. Private Const WM_LBUTTONDOWN = &H201
    20. Private Const WM_RBUTTONUP = &H205
    21.  
    22. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    23. Dim TrayI As NOTIFYICONDATA
    24. Private Sub Form_Load()
    25.     TrayI.cbSize = Len(TrayI)
    26.     'Set the window's handle (this will be used to hook the specified window)
    27.     TrayI.hWnd = pichook.hWnd
    28.     'Application-defined identifier of the taskbar icon
    29.     TrayI.uId = 1&
    30.     'Set the flags
    31.     TrayI.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    32.     'Set the callback message
    33.     TrayI.ucallbackMessage = WM_LBUTTONDOWN
    34.     'Set the picture (must be an icon!)
    35.     TrayI.hIcon = imgIcon(2).Picture
    36.     'Set the tooltiptext
    37.     TrayI.szTip = "Recent" & Chr$(0)
    38.     'Create the icon
    39.     Shell_NotifyIcon NIM_ADD, TrayI
    40.  
    41.     Me.Hide
    42. End Sub
    43. Private Sub Form_Unload(Cancel As Integer)
    44.     'remove the icon
    45.     TrayI.cbSize = Len(TrayI)
    46.     TrayI.hWnd = pichook.hWnd
    47.     TrayI.uId = 1&
    48.     Shell_NotifyIcon NIM_DELETE, TrayI
    49.     End
    50. End Sub
    51. Private Sub mnuPop_Click(Index As Integer)
    52.     Select Case Index
    53.         Case 0
    54.             MsgBox "KPD-Team 1998" + Chr$(13) + "URL: [url]http://www.allapi.net/[/url]" + Chr$(13) + "E-Mail: [email][email protected][/email]", vbInformation + vbOKOnly
    55.         Case 2
    56.             Unload Me
    57.     End Select
    58. End Sub
    59. Private Sub pichook_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    60.     Msg = X / Screen.TwipsPerPixelX
    61.     If Msg = WM_LBUTTONDBLCLK Then
    62.         'Left button double click
    63.         mnuPop_Click 0
    64.     ElseIf Msg = WM_RBUTTONUP Then
    65.         'Right button click
    66.         Me.PopupMenu mnuPopUp
    67.     End If
    68. End Sub
    69. Private Sub Timer1_Timer()
    70.     Static Tek As Integer
    71.     'Animate the icon
    72.     Me.Icon = imgIcon(Tek).Picture
    73.     TrayI.hIcon = imgIcon(Tek).Picture
    74.     Tek = Tek + 1
    75.     If Tek = 3 Then Tek = 0
    76.     Shell_NotifyIcon NIM_MODIFY, TrayI
    77. End Sub

    or see http://www.vb-world.net/tips/tip61.html

  3. #3
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Use this:


    VB Code:
    1. Private WithEvents TI As cTrayIcon
    2.  
    3. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    4.     If UnloadMode = vbFormControlMenu Then
    5.         'I don't want to terminate the app
    6.        
    7.         Set TI = New cTrayIcon
    8.         With TI
    9.             .SetPct pctTray
    10.             .CreateIcon "This is my app"
    11.         End With
    12.         Me.Hide
    13.         Cancel = 1
    14.     End If
    15.    
    16. End Sub
    17.  
    18.  
    19. Private Sub TI_TrayIconDoubleCLick()
    20.     TI.DeleteIcon
    21.     Set TI = Nothing
    22.     Me.Show
    23. End Sub
    24.  
    25. Private Sub Form_Unload(Cancel As Integer)
    26.     TI.DeleteIcon
    27.     Set TI = Nothing
    28.                    
    29. End Sub

    pctTray is a picturebox (invisible) with the icon you want to show in the Systray.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    Member
    Join Date
    May 1999
    Location
    St. Louis, MO, USA
    Posts
    54

    Question

    mc Brain,
    what is or where do I find cTrayIcon? I'm assuming it's a class that I need to reference.
    jen

  5. #5
    Member
    Join Date
    May 1999
    Location
    St. Louis, MO, USA
    Posts
    54

    Exclamation OOps

    I got it
    jen

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by Jennifer_R
    mc Brain,
    what is or where do I find cTrayIcon? I'm assuming it's a class that I need to reference.
    It's a Class I created, based on some examples I found over here... and I guess you've already found it attached on my previous reply.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  7. #7
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    If you all think this will help you, I've written a wrapper to send forms to the system tray.

    I have it attached.

    On your form, make a non-visible menu titled:
    trayPopup

    (no mnu prefix).

    Then, to add the form to the system tray, call:
    GotoTray Me

    The first time (like on form load)

    And then to actually show it in the system tray any time other than the first (although doing it again does not hurt):
    ShowInTray Me, True

    And to hide it from the tray (like in the form_queryUnload function):
    ShowInTray Me, False

    Also, make sure that you onload the tray icon before exiting the program or a ghost will remain in the tray.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  8. #8
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Umm, forgot to actually attach the file (whoops)
    Attached Files Attached Files
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  9. #9
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Don't you need to add the call to CheckTray sub on the MouseDown event or similar as well to get the popmenu shown??
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  10. #10
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    ** Looks around nervously **

    Umm yeah, I should probably comment my code better:

    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Static lngMsg As Long
        Static blnFlag As Boolean
        Dim result As Long
        lngMsg = X / Screen.TwipsPerPixelX
        If lngMsg = WM_LBUTTONDBLCLICK Or lngMsg = WM_RBUTTONUP Then
    '      tmp = tmp
        End If
        CheckTray Me, lngMsg, blnFlag, result
    End Sub
    I'm pretty sure that's everything (now)

    Another point:
    The name of the form will be the tool-tip for the tray icon.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  11. #11
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by Lord_Rat

    Another point:
    The name of the form will be the tool-tip for the tray icon.
    You could use its tag instead, just in case you want another tooltip for the icon.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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