Hi all,
I'm trying to write an application that will detect screen updates and send them across to a monitor station. It's effectively like a VNC application, but the supervisors here want to recieve more information than VNC provides, for training and monitoring purposes.
So, what I'm trying to get is how to use SetWindowsHookEx to grab all paint messages that occur on-screen, so that I can then grab the update rectangle and send it down the wire.
I think I need to use WH_GETMESSAGE and then trap the WM_Paint messages (&HF) that come in to the delegate procedure, but I'm not getting anything through at all.
Here's the source:
[tt]Delegate Function msgHookDelegate(ByVal Code As Integer, ByVal wParam As Integer, ByVal lParam As MSGHookStruct) As Integer
<MarshalAs(UnmanagedType.FunctionPtr)> _
Private msgCallBackDel As msgHookDelegate
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook As Integer, ByVal lpfn As msgHookDelegate, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As MSGHookStruct) As Integer
Structure MSGHookStruct
Public hwnd As Long
Public message As Long
Public wParam As Long
Public lParam As Long
Public time As Long
Public pt As POINTAPI
End Structure
Public msgHandle As Integer
Public Sub HookPaintMessages()
msgCallBackDel = New msgHookDelegate(AddressOf MessageCallback)
msgHandle = SetWindowsHookEx(WH_GETMESSAGE, msgCallBackDel, Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
End Sub
Public Function MessageCallback(ByVal Code As Integer, ByVal wParam As Integer, ByVal lParam As MSGHookStruct) As Integer
console.writeline("Message Callback. Code=" & Code)
Return CallNextHookEx(msgHandle , Code, wParam, lParam)
End Function[/tt]
Any help with why this isn't working would be very much appreciated!
Corin
I'm trying to write an application that will detect screen updates and send them across to a monitor station. It's effectively like a VNC application, but the supervisors here want to recieve more information than VNC provides, for training and monitoring purposes.
So, what I'm trying to get is how to use SetWindowsHookEx to grab all paint messages that occur on-screen, so that I can then grab the update rectangle and send it down the wire.
I think I need to use WH_GETMESSAGE and then trap the WM_Paint messages (&HF) that come in to the delegate procedure, but I'm not getting anything through at all.
Here's the source:
[tt]Delegate Function msgHookDelegate(ByVal Code As Integer, ByVal wParam As Integer, ByVal lParam As MSGHookStruct) As Integer
<MarshalAs(UnmanagedType.FunctionPtr)> _
Private msgCallBackDel As msgHookDelegate
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook As Integer, ByVal lpfn As msgHookDelegate, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As MSGHookStruct) As Integer
Structure MSGHookStruct
Public hwnd As Long
Public message As Long
Public wParam As Long
Public lParam As Long
Public time As Long
Public pt As POINTAPI
End Structure
Public msgHandle As Integer
Public Sub HookPaintMessages()
msgCallBackDel = New msgHookDelegate(AddressOf MessageCallback)
msgHandle = SetWindowsHookEx(WH_GETMESSAGE, msgCallBackDel, Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
End Sub
Public Function MessageCallback(ByVal Code As Integer, ByVal wParam As Integer, ByVal lParam As MSGHookStruct) As Integer
console.writeline("Message Callback. Code=" & Code)
Return CallNextHookEx(msgHandle , Code, wParam, lParam)
End Function[/tt]
Any help with why this isn't working would be very much appreciated!
Corin