Public Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (Optional ByVal lpModuleName As String) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Public Const WH_JOURNALRECORD = 0
Public Const WH_JOURNALPLAYBACK = 1
Public Const WH_KEYBOARD = 2
Public Const WH_GETMESSAGE = 3
Public Const WH_CALLWNDPROC = 4
Public Const WH_CBT = 5
Public Const WH_SYSMSGFILTER = 6
Public Const WH_MOUSE = 7
Public Const WH_HARDWARE = 8
Public Const WH_DEBUG = 9
Public Const WH_SHELL = 10
Public Const WH_FOREGROUNDIDLE = 11
Public Const HCBT_CREATEWND = 3
Public Const HCBT_DESTROYWND = 4
Public Const HCBT_ACTIVATE = 5
Public Const HSHELL_WINDOWCREATED = 1
Public Const HSHELL_WINDOWDESTROYED = 2
Public Const HSHELL_ACTIVATESHELLWINDOW = 3
Private Type CREATESTRUCT
lpCreateParams As Long
hInstance As Long
hMenu As Long
hWndParent As Long
cy As Long
cx As Long
y As Long
x As Long
style As Long
lpszName As String
lpszClass As String
ExStyle As Long
End Type
Private Type CBT_CREATEWND
lpcs As CREATESTRUCT
hWndInsertAfter As Long
End Type
Private Type CBTACTIVATESTRUCT
fMouse As Long
hWndActive As Long
End Type
Private hHook As Long
Private wCode As Long
Private x As formTask
Public Function HookProc(nCode As Long, wParam As Long, lParam As Long)
If nCode < 0 Then
HookProc = CallNextHookEx(hHook, nCode, wParam, lParam)
Exit Function
End If
If wCode = WH_SHELL Then
If nCode = HSHELL_WINDOWCREATED Or nCode = HSHELL_WINDOWDESTROYED Then
x.GeWindows
End If
End If
If wCode = WH_CBT Then
If nCode = HCBT_CREATEWND Or nCode = HCBT_DESTROYWND Or nCode = HCBT_ACTIVATE Then
x.GeWindows
End If
End If
HookProc = CallNextHookEx(hHook, nCode, wParam, lParam)
End Function
Public Function StartHook()
Set x = New formTask
wCode = WH_SHELL
hHook = SetWindowsHookEx(wCode, AddressOf HookProc, GetModuleHandle, 0)
x.Show 1
End Function
Public Function EndHook()
If hHook > 0 Then
UnhookWindowsHookEx hHook
End If
Set x = Nothing
End Function