Thanks for any help on this one...
Trying to find a way to detect the creation or activation of msgbox's and dialog forms created by other applications. If possible I'd prefer to do this without running a timer and checking EnumWindows, somehow raising an event when these windows appear.
So far I've tried hooking the windows shell (RegisterWindowMessage API) which detects others windows great but not MsgBox's.
Any other ideas?
Trying to find a way to detect the creation or activation of msgbox's and dialog forms created by other applications. If possible I'd prefer to do this without running a timer and checking EnumWindows, somehow raising an event when these windows appear.
So far I've tried hooking the windows shell (RegisterWindowMessage API) which detects others windows great but not MsgBox's.
Any other ideas?
Code:
Option Explicit
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Const GWL_WNDPROC = -4
Const HSHELL_WINDOWCREATED = 1
Const HSHELL_WINDOWDESTROYED = 2
Const HSHELL_ACTIVATESHELLWINDOW = 3
Const HSHELL_WINDOWACTIVATED = 4
Const HSHELL_GETMINRECT = 5
Const HSHELL_REDRAW = 6
Const HSHELL_TASKMAN = 7
Const HSHELL_LANGUAGE = 8
Const HSHELL_SYSMENU = 9
Const HSHELL_ENDTASK = 10
Const HSHELL_ACCESSIBILITYSTATE = 11
Const HSHELL_APPCOMMAND = 12
Const HSHELL_WINDOWREPLACED = 13
Const HSHELL_WINDOWREPLACING = 14
Const HSHELL_HIGHBIT = 15
Const HSHELL_FLASH = 16
Const HSHELL_RUDEAPPACTIVATED = 17
Dim myPid As Long, lpWndProc As Long, WM_SHELLHOOK As Long
Public Sub SetupWindowHook(FormHwnd As Long)
WM_SHELLHOOK = RegisterWindowMessage("SHELLHOOK")
lpWndProc = SetWindowLong(FormHwnd, GWL_WNDPROC, AddressOf WndProc)
myPid = GetCurrentProcessId
End Sub
Private Function WndProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Debug.Print hwnd, msg, wParam, lParam
WndProc = CallWindowProc(lpWndProc, hwnd, msg, wParam, lParam)
End Function