Solved

Set a hook to intercept WM_COMMAND sent from a menu

Posted on 2004-10-14
6
945 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:ricardog2
  • 4
  • 2
6 Comments
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12320124
>>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
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 250 total points
ID: 12320128
0
 
LVL 1

Author Comment

by:ricardog2
ID: 12321721
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.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:ricardog2
ID: 12322763
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.
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12327828
'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).


0
 
LVL 17

Expert Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 211
VB error "Type mismatch" 2 60
VB6 ListBox Question 4 49
VB script to continue despite error 2 16
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question