Results 1 to 10 of 10

Thread: Load into tray

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    301

    Load into tray

    Hi there,

    Thanks to this beautiful forum I have this for SyStray:

    VB Code:
    1. Option Explicit
    2.  
    3. '// FORM
    4.  
    5. Private Sub Form_Load()
    6.     mTray.Refresh Me                                    ' TRAY ICON LOAD
    7.  
    8. End Sub
    9.  
    10. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    11.     mTray.Click Me, X                                   ' TRAY ICON CLICK
    12. End Sub
    13.  
    14. Private Sub Form_Resize()
    15.     mTray.Resize Me                                     ' TRAY ICON SHOW/HIDE
    16. End Sub
    17.  
    18. Private Sub Form_Unload(Cancel As Integer)
    19.     mTray.Destroy                                       ' TRAY ICON CLOSE
    20. End Sub
    21.  
    22. Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
    23.  
    24. End Sub

    And this in a module

    VB Code:
    1. Option Explicit
    2.  
    3. Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    4.  
    5. Public Type NOTIFYICONDATA
    6.     cbSize As Long
    7.     hwnd As Long
    8.     uId As Long
    9.     uflags As Long
    10.     uCallBackMessage As Long
    11.     hIcon As Long
    12.     szTip As String * 64
    13. End Type
    14.  
    15. Public nid As NOTIFYICONDATA
    16.  
    17. Private FX As Single
    18. Private FY As Single
    19.  
    20. Const NIM_ADD = &H0
    21. Const NIM_MODIFY = &H1
    22. Const NIM_DELETE = &H2
    23. Const WM_MOUSEMOVE = &H200
    24. Const NIF_MESSAGE = &H1
    25. Const NIF_ICON = &H2
    26. Const NIF_TIP = &H4
    27. Const WM_LBUTTONDBLCLK = &H203
    28. Const WM_LBUTTONDOWN = &H201
    29. Const WM_LBUTTONUP = &H202
    30. Const WM_RBUTTONDBLCLK = &H206
    31. Const WM_RBUTTONDOWN = &H204
    32. Const WM_RBUTTONUP = &H205
    33.  
    34. Public Sub Refresh(ByVal frm As Form)
    35.     FX = frm.Width
    36.     FY = frm.Height
    37.     nid.cbSize = Len(nid)
    38.     nid.hwnd = frm.hwnd
    39.     nid.uId = vbNull
    40.     nid.uflags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    41.     nid.uCallBackMessage = WM_MOUSEMOVE
    42.     nid.hIcon = frm.Icon
    43.     nid.szTip = App.Title & vbNullChar
    44.     Call Shell_NotifyIcon(NIM_ADD, nid)
    45. End Sub
    46.  
    47. Public Sub Click(ByVal frm As Form, ByVal X As Single)
    48.     Dim Msg As Long
    49.     Dim sFilter As String
    50.     Msg = X / Screen.TwipsPerPixelX
    51.     Select Case Msg
    52.         Case WM_LBUTTONDOWN
    53.             frm.WindowState = 0
    54.             frm.Show
    55.         Case WM_LBUTTONUP
    56.         Case WM_LBUTTONDBLCLK
    57.         Case WM_RBUTTONDOWN
    58.         Case WM_RBUTTONUP
    59.         Case WM_RBUTTONDBLCLK
    60.     End Select
    61. End Sub
    62.  
    63. Public Sub Resize(ByVal frm As Form)
    64.     If frm.WindowState = 1 Then
    65.         frm.Hide
    66.         frm.WindowState = 0
    67.     ElseIf frm.WindowState = 0 Then
    68.         frm.Show
    69.         frm.Width = FX
    70.         frm.Height = FY
    71.     End If
    72. End Sub
    73.  
    74. Public Sub Destroy()
    75.     Call Shell_NotifyIcon(NIM_DELETE, nid)
    76. End Sub
    77.  
    78. Now I want, that if i run the program, that the Form1 WONT be visible but will be visible if I hit it in the Tray Icon?
    79. So that it runs into tray, and you can 'open' it from tray..
    80.  
    81. How to?

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Load into tray

    Delete what you have in Form_Load and Form_Resize and try this:

    VB Code:
    1. Private Sub Form_Load()
    2.     Me.WindowState = 1
    3. End Sub
    4.  
    5. Private Sub Form_Resize()
    6.     If Me.WindowState = 1 Then
    7.         mTray.Refresh Me
    8.     Else
    9.         mTray.Destroy
    10.     End If
    11. End Sub
    Now the icon appears in tray only when you minimize the window, and if you click on it, window is restored, and icon dissapeares - that's just my idea about the tray icon

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    301

    Re: Load into tray

    Thnx, but I had a another idea...

    I want, if I hit myapp.exe that u wont see any form, but only a icon into tray
    And if u hit that, then it will 'show' form1... :]

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Load into tray

    Yes, just edited my previous post Didn't read it carefully before. Basic idea is that the startup form must be minimized at startup. You can do that at design time by seting it's WindowState property to 1, or at runtime, as explained in my previous post.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    301

    Re: Load into tray

    ok, that works.
    I thank you :]:]:]

  6. #6

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    301

    Re: Load into tray

    lol, now I have a little other problem.
    I want it isnt in the task bar?
    [like maps, programs...]
    only into the tray
    So if i start my comp, and it loads my program[already fixed that] I want ONLY see it in tray[like time] and not in the taskbar...

  8. #8
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: Load into tray

    did you set the form property for show in taksbar?

    Good Luck!

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    301

    Re: Load into tray

    lol, no didnt do that.
    But Now I have, thank you :]

  10. #10
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Load into tray

    Set ShowInTaskbar=False (on a Form). But i think that the code already works that way.

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