Solved

Set a hook to intercept WM_COMMAND sent from a menu

Posted on 2004-10-14
6
943 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

785 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