Question

Is am using this:

SetWindowsHookEx(WH_CALLWNDPROC, ...);

I can see the messages I want to process, but I want to prevent those message from reaching the target window. So I tried this:

SetWindowsHookEx(WH_GETMESSAGE, ...);

When I do this I can modify the message, and prevent the target window from processing it, but this hook doesn't see the messages I need to process. I presume this is because it is being posted to the target window's queue, not sent? Is there a way around this issue? I have heard that window sub-classing might be able to accomplish this, but can I subclass a window in a different process? Is there a way to do this using hooks?

Was it helpful?

Solution

You can't subclass a window in a another process, but the hook DLL should be able to subclass the window you're interested in. WH_GETMESSAGE and WH_CALLWNDPROC hooks run in the context of the process receiving the message, so at that point you have an "in" to subclass the target's window.

OTHER TIPS

You could try subclassing the target window and then filter the messages.

The hook documentation suggests this can't be done but I assume this strategy might work: use SetWindowsHookEx(WH_CALLWNDPROC, ... )

In the procedure just modify the message you want to throw away to an unused WM_ value.

LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam)
{
   CWPSTRUCT *C=(CWPSTRUCT *)lParam;

   if ( ...we are interested in this one) {
     ..deal with this message here...
     //Modify the message so that the client will ignore it
     C->message=WM_USER+44; //presumably ignored by client
   }       
   return GetNextHook(...);
}

Nasty but easy?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top