Solved

Set a hook to intercept WM_COMMAND sent from a menu

Posted on 2004-10-14
6
938 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
Comment Utility
>>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
Comment Utility
0
 
LVL 1

Author Comment

by:ricardog2
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:ricardog2
Comment Utility
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
Comment Utility
'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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now