forked from lee-soft/ViPad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SystemNotificationManager.cls
68 lines (56 loc) · 2.19 KB
/
SystemNotificationManager.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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "SystemNotificationManager"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Implements IHookSink
' Member variables
Private m_hWndHidden As Long
Public Event QueryEndSession(ByVal Flag As EndSessionFlags, Cancel As Boolean)
Public Event EndSession(ByVal EndingInitiated As Boolean, ByVal Flag As EndSessionFlags)
' *********************************************
' Initialize/Terminate
' *********************************************
Private Sub Class_Initialize()
' Hook into hidden toplevel message stream.
m_hWndHidden = FindHiddenTopWindow()
Call HookWindow(m_hWndHidden, Me)
End Sub
Private Sub Class_Terminate()
UnhookWindow m_hWndHidden
End Sub
Private Function IHookSink_WindowProc(hWnd As Long, msg As Long, wParam As Long, LParam As Long) As Long
Dim Cancel As Boolean
Dim EatIt As Boolean
Select Case msg
Case WM_ENDSESSION
' wParam confirms end, lParam provides reason flag.
' If the session is being ended, wParam is TRUE; the session
' can end any time after all applications have returned from
' processing this message. Otherwise, it is FALSE.
RaiseEvent EndSession(CBool(wParam), LParam)
Case WM_QUERYENDSESSION
' lParam provides flag that indicates reason for ending.
RaiseEvent QueryEndSession(LParam, Cancel)
' Applications should respect the user's intentions and
' return TRUE. By default, the DefWindowProc function
' returns TRUE for this message.
' If shutting down would corrupt the system or media that
' is being burned, the application can return FALSE.
IHookSink_WindowProc = Abs(Not Cancel)
EatIt = True
End Select
If Not EatIt Then
' Just allow default processing for everything else.
IHookSink_WindowProc = _
InvokeWindowProc(hWnd, msg, wParam, LParam)
End If
End Function