Solved

Set a hook to intercept WM_COMMAND sent from a menu

Posted on 2004-10-14
6
946 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

734 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