0

I would like to write an application which passes every message it receives to another window. For example, I have an application where user can press some keys, move mouse over it, etc. and I want all these messages passed to, for example, MS Paint.

How do I do this? Any ideas? As far as I know, there may be a problem with sending key strokes to another window, so please advice as well.

EDIT

Okay, maybe I will give you more description of what I'm looking for.

My applications displays a window of another application on the form. Now I would like to control the other window using messages sent to my application's form (like key downs, mouse moves, etc.).

I have been thinking of passing all the messages my form receives to the window of the application I'm kind of 'embedding' into my own. By 'embedding' I mean making the application window display on my form.

Maybe there's another solution to my problem. Please advice.

Thank you for your time.

Pateman
  • 2,727
  • 3
  • 28
  • 43

3 Answers3

4

Some messages (i.e. input messages) arrive through the message queue and the rest are delivered straight to the recipient windows. What you are asking to do therefore requires you to do all of the following:

  1. Implement a top level message loop that retrieves messages from the queue and sends them to the other app.
  2. Reimplement all modal window loops to pass all messages on.
  3. Replace the window procedure for all windows in your process with one that passes all messages on to the other app.
  4. Look for other opportunities for messages to arrive that I have not covered.

I can't imagine that this is really going to be the solution to your problem, whatever that problem is.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I like the first idea, can you elaborate? Is there any difference between a normal message loop and a top level one? – Pateman Sep 22 '11 at 14:16
  • @Pateman By top-level message loop I mean the loop that is invoked by Application.Run in a Delphi app. Other message loops are run when you show modal windows. I trust you are aware of the difference between queued and non-queued messages? Only queued messages can be reached from the message loop. Non-queued messages arrive at each window's window procedure. – David Heffernan Sep 22 '11 at 14:21
  • 1
    @Pateman: David's list was not suggestions for alternatives (a "pick one you like"). You have to do *all* of those things (at least steps #1-3), and investigate #4. – Ken White Sep 22 '11 at 14:35
1

Forwarding the messages is definitely possible and easy, but it likely won't do what you are expecting. Take a look here.

Mike Kwan
  • 24,123
  • 12
  • 63
  • 96
1

Override the form's DefaultHandler() and post every message it gets to the other form. If there are any explicit message handlers in the form or even some controls then you may not see those messages in DefaultHandler().

Jerry Gagnon
  • 1,131
  • 8
  • 16