I completely can't get into Winhooks! If I am right, the message handlers are some kind of a hooking mechanism that is the same as, for example, journal hook. I am speaking about windows 'WM_' messages and their 'OnMessage' handlers. If I am right, we can get the list of installed hooks (all - system and message) by just the use of some hooking functions. I seem to speak very tough, but what I would like to ask you is: what is a structural difference between message handlers (WM_...) and hooks (global/private)? They do just the same work - pass the control to the user procedure, but still they seem not be the same.
Posted on 2002-08-19 07:18:57 by Maestro

I don't personally have much use for HOOK procedures but the general idea is that they are something like a subclass for a control or a callback procedure but for a system function.

The idea is simple enough, you write a procedure with the correct parameter count and type and then set up the HOOK procedure so that it points to the procedure that you have written.

You then process the information that comes to the procedure you have written and pass the unused info to the next hook in the system.


Posted on 2002-08-19 09:04:37 by hutch--
Hooks are the only accepted method for an external module, one in a foreign process, to view the messages passing through another app. You have to get the kernel's permission to register your function in the chain of hooks, and your hook gets the same info all the other functions in the chain do. A message handler is the theoretical top level for message handling, and only one true callback function should exist for a given message, whereas the kernel can have an infinite list of hooks perusing the info at any given time.

I use hooks to create macro-type apps (i.e. hit F10 in AIM and my hooked app sends a full line of text to the active window). Everything I learned about hooks came from the Hook.dll example in the MSDN. It is really easy to understand--unusual for Microsoft examples--and pretty simple to port.

Hope this helps,
Posted on 2002-08-20 08:17:04 by mistersulu
Iczelion has some ok info on the subject too. That's where I learned (well, that and the win32 + hands on experience).

Posted on 2002-08-20 08:43:01 by Fake51
heres some code to help you use hooks.

Enable Proc
Invoke FindWindow,0,Addr aim ;;window name
cmp eax,0 ;if its 0
jne @F ; jump if its not xero
xor eax,eax; wasnt found
ret; return
mov aimWnd,eax
Invoke GetWindowThreadProcessId,eax,0
mov aimThreadId,eax
Invoke SetWindowsHookEx, WH_KEYBOARD ,Offset KeyboardProc,hInstDLL,aimThreadId
mov hMapObject,eax
xor eax,eax
Enable EndP

KeyboardProc Proc nCode :DWORDwParam :DWORD,LPARAMa :DWORD
.If nCode == HC_ACTION
.If wParam == VK_F12; do stuff if f12 ifs pressed

; stuff here

Invoke CallNextHookEx,hMapObject,nCode,wParam,LPARAMa; must be here

KeyboardProc EndP

;here are your choises for hook types
Posted on 2002-08-20 12:55:32 by Qages