WndProc Message Forwarding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pigeonrandle@hotmail.com

    WndProc Message Forwarding

    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.

  • Lowell Heddings

    #2
    Re: WndProc Message Forwarding


    pigeonrandle@ho tmail.com wrote:
    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.

    Comment

    • Stanimir Stoyanov

      #3
      RE: WndProc Message Forwarding

      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.H Wnd, m.Msg, m.WParam, m.LParam);

      I hope this helps you.
      --
      Best regards,

      Stanimir Stoyanov
      admin@nospam.st oyanoff.info


      "pigeonrandle@h otmail.com" wrote:
      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.
      >
      >

      Comment

      • pigeonrandle@hotmail.com

        #4
        Re: WndProc Message Forwarding

        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 :-)

        Comment

        • Stanimir Stoyanov

          #5
          Re: WndProc Message Forwarding

          Yes, you can check if the Msg ID is one of these and simply not redirect them.
          --
          Best regards,

          Stanimir Stoyanov
          admin@nospam.st oyanoff.info


          "pigeonrandle@h otmail.com" wrote:
          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 :-)
          >
          >

          Comment

          • pigeonrandle@hotmail.com

            #6
            Re: WndProc Message Forwarding

            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.





            Stanimir Stoyanov wrote:
            Yes, you can check if the Msg ID is one of these and simply not redirect them.
            --
            Best regards,
            >
            Stanimir Stoyanov
            admin@nospam.st oyanoff.info
            >
            >
            "pigeonrandle@h otmail.com" wrote:
            >
            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 :-)

            Comment

            • Mattias Sjögren

              #7
              Re: WndProc Message Forwarding

              >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

              --
              Mattias Sjögren [C# MVP] mattias @ mvps.org
              http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
              Please reply only to the newsgroup.

              Comment

              • pigeonrandle@hotmail.com

                #8
                Re: WndProc Message Forwarding

                Mattias,
                Cheers for replying. Do you have any ideas what these APIs are?

                James

                Mattias Sjögren wrote:
                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
                >
                --
                Mattias Sjögren [C# MVP] mattias @ mvps.org
                http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
                Please reply only to the newsgroup.

                Comment

                Working...