Link to home
Start Free TrialLog in
Avatar of ricardog2
ricardog2

asked on

Set a hook to intercept WM_COMMAND sent from a menu

Hello,

I have an ActiveX DLL which is loaded by an application (MSN Messenger) in the same thread. I want the DLL to know when the button "Send File" in the application is pressed.

Using Spy++, I've found that it generates this message when the button is pressed:
000C044A P WM_COMMAND wNotifyCode:0 (sent from a menu) wID:40275 [wParam:00009D53 lParam:00000000]

How can I intercept that message from the DLL?

I've tried WH_MSGFILTER and WH_GETMESSAGE hooks but they do not seem to fire when the button is pressed. Any ideas?
Avatar of zzzzzooc
zzzzzooc

>>but they do not seem to fire when the button is pressed.
Are you sure the hook installs correctly? I'm not sure if the application would have access to a procedure in your EXE or not.

Alternatively, you can try to cross-process subclass the actual Button's window to receive the WM_COMMAND.

http://Q_21164345.html#12295292
ASKER CERTIFIED SOLUTION
Avatar of zzzzzooc
zzzzzooc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ricardog2

ASKER

I've used the examples available at http://www.oreilly.com/catalog/subhookvb/ to install the hooks. I get messages when I click on the menu or drag the window, but I'm not sure which kind of hook is needed to intercept that specific message.

Also, my procedure is in the same thread as the EXE (I've compared the App.ThreadID to the EXE's one listed in Spy++), so it should work without a cross-process hook. Anyway, I'll try that.

Thanks for the answer.
I got it working! It really was WH_GETMESSAGE, but the oreilly's example code had to be modified a bit to get the message correctly.

Since I've found the problem with the DLL you've suggested, I'll give you the points.
'grats. Also, in case you haven't gotten to it, you may have the get the high/low bits for wParam (or lParam.. forgot) to know which button notification (BN) was sent (such as BN_CLICKED).


Unless you meant a menu-item instead of a button (doh). Just woke up so I'm a bit dazed.. lol :)