-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdvSysTray.cls
220 lines (179 loc) · 5.57 KB
/
AdvSysTray.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "AdvSysTray"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const NIF_STATE = &H8
Private Const NIF_INFO = &H10
Private Const NIF_ALL = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_USER = &H400
Private Const NIN_BALLOONSHOW = WM_USER + 2
Private Const NIN_BALLOONHIDE = WM_USER + 3
Private Const NIN_BALLOONTIMEOUT = WM_USER + 4
Private Const NIN_BALLOONUSERCLICK = WM_USER + 5
Private Const NOTIFYICONDATA_V1_SIZE = 88
Public Enum NIIF
NIIF_NONE = &H0
NIIF_INFO = &H1
NIIF_WARNING = &H2
NIIF_ERROR = &H3
NIIF_NOSOUND = &H10
End Enum
Private Type DLLVERSIONINFO
cbSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformID As Long
End Type
Private Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 128
dwState As Long
dwStateMask As Long
szInfo As String * 256
uTimeoutVersion As Long
szInfoTitle As String * 64
dwInfoFlags As Long
End Type
Private lVersion As Long
Private iTipSize As Integer
Private fCreated As Boolean
Private WithEvents frmOwner As Form
Attribute frmOwner.VB_VarHelpID = -1
Private nid As NOTIFYICONDATA
Private Declare Function DllGetVersion Lib "shell32" (dwVersion As DLLVERSIONINFO) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Public Event LButtonDown()
Public Event LButtonUp()
Public Event LButtonDblClk()
Public Event RButtonDown()
Public Event RButtonUp()
Public Event RButtonDblClk()
Public Event BalloonShow()
Public Event BalloonHide()
Public Event BalloonTimeout()
Public Event BalloonUserClick()
Private Sub Class_Initialize()
Dim dvi As DLLVERSIONINFO
fCreated = False
dvi.cbSize = Len(dvi)
On Error Resume Next
DllGetVersion dvi
On Error GoTo 0
lVersion = dvi.dwMajorVersion
iTipSize = IIf(lVersion < 5, 63, 127)
End Sub
Private Sub Class_Terminate()
Destroy
End Sub
Public Property Get ShellVersion() As Long
ShellVersion = lVersion
End Property
Public Property Let Icon(ByVal Icon As StdPicture)
If Not fCreated Then Exit Property
nid.hIcon = Icon
Shell_NotifyIcon NIM_MODIFY, nid
End Property
Public Property Get Icon() As StdPicture
If Not fCreated Then Exit Property
Icon = nid.hIcon
End Property
Public Property Let Tooltip(ByVal Tooltip As String)
If Not fCreated Then Exit Property
nid.szTip = Left$(Tooltip, iTipSize) & vbNullChar
Shell_NotifyIcon NIM_MODIFY, nid
End Property
Public Property Get Tooltip() As String
If Not fCreated Then Exit Property
Tooltip = Left$(nid.szTip, InStr(nid.szTip, vbNullChar) - 1)
End Property
Public Sub Create(ByVal Owner As Form)
If fCreated Then Exit Sub
Set frmOwner = Owner
With nid
If lVersion >= 5 Then
.cbSize = Len(nid)
.uFlags = NIF_ALL Or NIF_INFO
Else
.cbSize = NOTIFYICONDATA_V1_SIZE
.uFlags = NIF_ALL
End If
.hWnd = frmOwner.hWnd
.uID = 1
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = frmOwner.Icon
.szTip = frmOwner.Caption & vbNullChar
End With
fCreated = CBool(Shell_NotifyIcon(NIM_ADD, nid))
End Sub
Public Sub Destroy()
If Not fCreated Then Exit Sub
fCreated = Not CBool(Shell_NotifyIcon(NIM_DELETE, nid))
Set frmOwner = Nothing
End Sub
Public Sub ShowBalloon(ByVal text As String, Optional ByVal Title As String = "", Optional ByVal Flags As NIIF = NIIF_NONE Or NIIF_NOSOUND)
If Not (fCreated And lVersion >= 5) Then Exit Sub
With nid
.szInfo = Left$(text, 255) & vbNullChar
.szInfoTitle = Left$(Title, 63) & vbNullChar
.dwInfoFlags = Flags
End With
Shell_NotifyIcon NIM_MODIFY, nid
End Sub
Public Sub HideBalloon()
If Not (fCreated And lVersion >= 5) Then Exit Sub
nid.szInfo = vbNullChar
Shell_NotifyIcon NIM_MODIFY, nid
End Sub
Private Sub frmOwner_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Select Case x / Screen.TwipsPerPixelX
Case WM_LBUTTONDOWN:
RaiseEvent LButtonDown
Case WM_LBUTTONUP:
RaiseEvent LButtonUp
Case WM_LBUTTONDBLCLK:
RaiseEvent LButtonDblClk
Case WM_RBUTTONDOWN:
RaiseEvent RButtonDown
Case WM_RBUTTONUP:
RaiseEvent RButtonUp
Case WM_RBUTTONDBLCLK:
RaiseEvent RButtonDblClk
Case NIN_BALLOONSHOW:
RaiseEvent BalloonShow
Case NIN_BALLOONHIDE:
RaiseEvent BalloonHide
Case NIN_BALLOONTIMEOUT:
RaiseEvent BalloonTimeout
Case NIN_BALLOONUSERCLICK:
RaiseEvent BalloonUserClick
End Select
End Sub