home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / systray / systray.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-10-10  |  3.3 KB  |  91 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Systray"
  5.    ClientHeight    =   495
  6.    ClientLeft      =   165
  7.    ClientTop       =   1515
  8.    ClientWidth     =   1560
  9.    Icon            =   "systray.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   495
  14.    ScaleWidth      =   1560
  15.    Begin VB.CommandButton Command1 
  16.       Caption         =   "Minimize to Systray"
  17.       Height          =   495
  18.       Left            =   0
  19.       TabIndex        =   0
  20.       Top             =   0
  21.       Width           =   1560
  22.    End
  23.    Begin VB.Menu mPopupSys 
  24.       Caption         =   "&SysTray"
  25.       Visible         =   0   'False
  26.       Begin VB.Menu mPopRestore 
  27.          Caption         =   "&Restore"
  28.       End
  29.       Begin VB.Menu mPopExit 
  30.          Caption         =   "&Exit"
  31.       End
  32.    End
  33. Attribute VB_Name = "Form1"
  34. Attribute VB_GlobalNameSpace = False
  35. Attribute VB_Creatable = False
  36. Attribute VB_PredeclaredId = True
  37. Attribute VB_Exposed = False
  38. Private Sub Command1_Click()
  39. Form1.WindowState = vbMinimized
  40. Shell_NotifyIcon NIM_ADD, nid 'Adds the cion to the SysTray
  41. End Sub
  42. Private Sub Form_Load()
  43. Me.Show 'Makes sure the form is shown
  44. With nid
  45. .cbSize = Len(nid)
  46. .hwnd = Me.hwnd
  47. .uID = vbNull
  48. .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  49. .uCallbackMessage = WM_MOUSEMOVE
  50. .hIcon = Me.Icon 'Sets the icon to show in the SysTray
  51. .szTip = "Your ToolTip" & vbNullChar 'change the Your ToolTip to what you want to show up as the tool tip for the icon in the SysTray
  52. End With
  53. End Sub
  54. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  55. Dim Result As Long, msg As Long 'Dims Result and msg as long for later use
  56. If Me.WindowState = 1 Then 'checks if the form is in the SysTray
  57. msg = x 'makes msg the x position of the mouse
  58. Select Case msg 'starts select block to see what the msg from the systray returns
  59. Case WM_LBUTTONUP 'check to see if the left mouse button was released
  60. Me.WindowState = vbNormal 'restores the form to normal state
  61. Result = SetForegroundWindow(Me.hwnd) 'Sets the form as a foreground window
  62. Me.Show 'Makes sure the form is shown
  63. Case WM_LBUTTONDBLCLK 'Checks to see if the left mouse button was double clicked
  64. Me.WindowState = vbNormal 'restores the form to normal state
  65. Result = SetForegroundWindow(Me.hwnd) 'Sets the form as a foreground window
  66. Me.Show 'Makes sure the form is shown
  67. Case WM_RBUTTONUP 'Checks to see if the right mouse button was released
  68. Result = SetForegroundWindow(Me.hwnd) 'Sets the form as a foreground window
  69. Me.PopupMenu Me.mPopupSys 'Pops up the menu when the right mouse button is released
  70. End Select 'Ends select block
  71. Else 'If the form isn't in the SysTray then
  72. msg = x / Screen.TwipsPerPixelX 'makes msg the position of the mouse divided by the sereen's twips per pixel on the x axies
  73. End If
  74. End Sub
  75. Private Sub Form_Resize()
  76. If Me.WindowState = vbMinimized Then Me.Hide
  77. End Sub
  78. Private Sub Form_Unload(Cancel As Integer)
  79. Shell_NotifyIcon NIM_DELETE, nid
  80. End Sub
  81. Private Sub mPopExit_Click()
  82. Shell_NotifyIcon NIM_DELETE, nid
  83. Unload Me
  84. End Sub
  85. Private Sub mPopRestore_Click()
  86. Me.WindowState = vbNormal
  87. Result = SetForegroundWindow(Me.hwnd)
  88. Me.Show
  89. Shell_NotifyIcon NIM_DELETE, nid
  90. End Sub
  91.