A1VBCode Forums

Apply hook to one process?


By Rohni - 10/27/2011

This is what I have so far and Im testing it out on my Vb app first but for some reason its not picking up the WM_SIZE message.

Does anyone know how I can do that or what I'm doing wrong?


Also if I could find Keiths VB Syntax Highlighter I would use it:

Public Type MSG

hwnd As Long

message As Long

wParam As Long

lParam As Long

time As Long


End Type

Public Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Public tempsize As Long

Public chromerect As RECT

Public win As Long

Public childwin As Long

Public classname As String

Public classlong As Long

Public Ret As Long

Private hMSGcb As Long

Private Const WH_GETMESSAGE As Long = 3

Private Const WM_SIZE As Long = &H5

Private 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

Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _

ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _

pDest As Any, pSource As Any, ByVal cb As Long)

Private Const WM_HOTKEY As Long = &H312

Private Const WM_SIZING As Long = &H214

Private Const WH_CALLWNDPROC As Long = 4

Private Const PM_REMOVE As Long = &H1

Private Function MSGCallback(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

If wParam Or lParam = WM_SIZE Then

MDIForm1.Caption = "Size"

End If

MSGCallback = CallNextHookEx(hMSGcb, Code, wParam, lParam)

End Function

Public Sub HookMSG()


hMSGcb = SetWindowsHookEx(WH_GETMESSAGE, AddressOf MSGCallback, App.hInstance, 0&)

'MDIForm1.Caption = "L:" & hMSGcb

End Sub

Public Sub UnhookMSG()

If hMSGcb <> 0 Then

Call UnhookWindowsHookEx(hMSGcb)

hMSGcb = 0

End If

End Sub

All of that is inside a module now could someone please explain to me why this is failing?