WndProc Message Forwarding

  • Thread starter Thread starter pigeonrandle
  • Start date Start date
P

pigeonrandle

Hi,
Does anyone know if there is a way to foward messages that a form
receives to another application form.
I was thinking i could override WndProc, but i don't know how to
forward any messages to another application?!

Any ideas greatfully appreciated (in advance!).
James Randle.
 
Hi,
Does anyone know if there is a way to foward messages that a form
receives to another application form.
I was thinking i could override WndProc, but i don't know how to
forward any messages to another application?!

Any ideas greatfully appreciated (in advance!).
James Randle.


You can forward messages by using SendMessage or PostMessage from the
Win32 API. Check pinvoke.net for the signatures.
 
Hello James,

Redirecting all of the messages that a form receives might not be a good
approach of what you would like to accomplish because messages such as
WM_PAINT contain information about that particular form's invalidated region.

If you still would like to do it, you can use the Win32 API SendMessage to
send the received message and its related parameters to another HWND -- the
handle to the desired window. You can find it using FindWindow if you know
its title and/or class name.

The P/Invoke signature for SendMessage and FindWindow can be found at
http://www.pinvoke.net/default.aspx/user32.SendMessage and
http://www.pinvoke.net/default.aspx/user32.FindWindow. Remember to include
the System.Runtime.InteropServices namespace to the file where you include
these functions' definitions.

You will have to override WndProc and make a call to SendMessage:

SendMessage(m.HWnd, m.Msg, m.WParam, m.LParam);

I hope this helps you.
 
Thankyou both for you rapid replies.

Stanimir, thanks for pointing out the 'unwanted' events. Presumably i
can just process these in WndProc as per normal?

Thanks again :-)
 
Hi again,
I've managed to get all the messages forwarding to a different
application window (notepad for simplicity), but they dont seem to be
processed properly. I can see them getting there in Spy++.

For instance, if i click on my form in the region that represents the
other applications mainmenu region, nothing happens!

Do i need to send the messages to different child windows depending on
their location? And if so, how can i get a handle to the menu?

So many questions!!
Again, thanks in advance.
 
I've managed to get all the messages forwarding to a different
application window (notepad for simplicity), but they dont seem to be
processed properly. I can see them getting there in Spy++.

You can't just blindly forward window messages to another application
and expect it to work. Many message parameters contain pointers and
handles that will be invalid in the other process.

For instance, if i click on my form in the region that represents the
other applications mainmenu region, nothing happens!

Do i need to send the messages to different child windows depending on
their location? And if so, how can i get a handle to the menu?

If you want to fake input in another application there are other APIs
to use.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top