i am making program that will monitor and log what button
controls are pressed in whole system (all posible programs),
i think the best way to do this is by using system wide hook,
but i am not sure which one should i use and also which
message should i track down
when someone press button on say calculator app, what message
is generated? is this message different if button is maded
using resource script than button created by winapi (CreateWindow())
also are those messages sent to parent window (of button)
on msg queue or directly to the windows procedure?

many thanks
Posted on 2002-06-21 06:58:59 by Mikky
When you click a button a lot of messages are generated, and they are different if you click with left mouse button or right. If you want to intercept the command given to the application you can grab WM_COMMAND message and check if HIWORD(wParam) is equal to BN_CLICKED notification code.
Posted on 2002-06-21 12:07:23 by LuHa
yes that message is exacly what i need
now what hook should i use?
is this message sent on message queue or directly to wnd procedure
Posted on 2002-06-21 12:24:05 by Mikky
If you're to log the button clicks, pick BM_CLICK or WM_COMMAND with BN_CLICKED. (You aren't going to log the button presses, do you?)

As for what to hook, I think both WH_CALLWNDPROCRET and WH_CALLWNDPROC work. WH_GETMESSAGE also meets the need but WH_CALLWNDPROCRET and WH_CALLWNDPROC are better imo.

If the user eventually uses the mouse and clicks on a button then the message is sent to message queue and then dispatched to the window procedure.
Posted on 2002-06-21 21:42:34 by C.Z.
I recently played a bit with hooks... I wasn't able to get WH_GETMESSAGE
to fire at all, but WH_CALLWNDPROC* seemed to work just fine.
Posted on 2002-06-22 05:03:25 by f0dder