Window connection questions

I am using this:

SetWindowsHookEx(WH_CALLWNDPROC, ...);

      

I see messages that I want to process, but I want the message not to go to the target window. So I tried this:

SetWindowsHookEx(WH_GETMESSAGE, ...);

      

When I do this, I can change the message and prevent the target window from processing it, but this hook doesn't see the messages that I need to process. I'm guessing this is because it is being sent to the application's window queue rather than dispatched? Is there a way to get around this problem? I heard that a window subclass might be able to accomplish this, but can I subclass the window in another process? Is there a way to do this using interceptors?

0


a source to share


3 answers


You cannot subclass a window in another process, but the sample DLL must be able to subclass the window of interest. The WH_GETMESSAGE and WH_CALLWNDPROC hooks are executed in the context of the process receiving the message, so you have an "in" to subclass the target window.



+1


a source


You can try subclassing the target window and then filtering the messages.



0


a source


The hook documentation suggests this is not possible, but I assume this strategy might work: use SetWindowsHookEx (WH_CALLWNDPROC, ...)

In the procedure, just change the message you want to throw to the 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(...);
}

      

Disgusting but easy?

0


a source







All Articles