forked from lee-soft/ViPad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SystemNotificationHelper.bas
70 lines (59 loc) · 2.33 KB
/
SystemNotificationHelper.bas
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
Attribute VB_Name = "SystemNotificationHelper"
Option Explicit
Private Declare Function EnumThreadWindows Lib "user32" (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
' QueryEndSession logoff options
Private Const ENDSESSION_SHUTDOWN As Long = &H0
Private Const ENDSESSION_CLOSEAPP As Long = &H1
Private Const ENDSESSION_CRITICAL As Long = &H40000000
Private Const ENDSESSION_LOGOFF As Long = &H80000000
Public Enum EndSessionFlags
esShutdown = ENDSESSION_SHUTDOWN
esCloseApp = ENDSESSION_CLOSEAPP
esCritical = ENDSESSION_CRITICAL
esLogoff = ENDSESSION_LOGOFF
End Enum
' *********************************************
' Public Methods
' *********************************************
Public Function FindHiddenTopWindow() As Long
' This function returns the hidden toplevel window
' associated with the current thread of execution.
Call EnumThreadWindows(App.ThreadID, AddressOf EnumThreadWndProc, VarPtr(FindHiddenTopWindow))
End Function
' *********************************************
' Private Methods
' *********************************************
Private Function EnumThreadWndProc(ByVal hWnd As Long, ByVal lpResult As Long) As Long
Dim nStyle As Long
Dim Class As String
' Assume we will continue enumeration.
EnumThreadWndProc = True
' Test to see if this window is parented.
' If not, it may be what we're looking for!
If GetWindowLong(hWnd, GWL_HWNDPARENT) = 0 Then
' This rules out IDE windows when not compiled.
Class = Classname(hWnd)
' Version agnostic test.
If InStr(Class, "Thunder") = 1 Then
If InStr(Class, "Main") = (Len(Class) - 3) Then
' Copy hWnd to result variable pointer,
Call CopyMemory(ByVal lpResult, hWnd, 4&)
' and stop enumeration.
EnumThreadWndProc = False
#If Debugging Then
Debug.Print Class; " hWnd=&h"; Hex$(hWnd)
Print #hLog, Class; " hWnd=&h"; Hex$(hWnd)
#End If
End If
End If
End If
End Function
Private Function Classname(ByVal hWnd As Long) As String
Dim nRet As Long
Dim Class As String
Const MaxLen As Long = 256
' Retrieve classname of passed window.
Class = String$(MaxLen, 0)
nRet = GetClassName(hWnd, Class, MaxLen)
If nRet Then Classname = Left$(Class, nRet)
End Function