How to send a message (with result) from child control to parent form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    How to send a message (with result) from child control to parent form?

    I've got an inherited panel on my form which overrides WndProc() and catches the 0x84 (WM_NCHITTEST) message. I do some processing on it and I'd like to know if there's a way to send that message, along with the result that I calculate, up to the parent form that contains the panel. I looked into the API method SendMessage(), but all you can send is the message (0x84), lparam and wparam, not the result (unless I'm missing something).

    Does anyone know a way I could do this? I want to use this panel to control the sizing and moving of the form. Right now I can size and move the panel just fine, as though it were its own window, but I need to send it up to the parent.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    This is out of my area of experience so I can only offer a general suggestion. Couldn't you also override the parent WndProc()?

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      I may be wrong, but I think the result goes into wparam and lparam somehow, doesn't it? To be honest, I've never used this.

      Having said that, since this is within your app, why not set up some delegates to pass data to the parent form?

      *Edit: err, it occurred to me that you might mean the parent class, if that's the case I have no idea. If you mean the parent form (that contains the control), then yes you should be able to use a delegate.

      Comment

      • HaLo2FrEeEk
        Contributor
        • Feb 2007
        • 404

        #4
        I could override the parent WndProc too, but it's not receiving the message, the panel is. I want to catch the message with the panel, calculate the result, and send it to the parent, so that when I resize the panel control, the parent form is resized as well.

        The form contains the inherited panel, I access the parent with Parent.[property], but it sees the parent as a control and not as a form, so I can't access its wndproc or any other methods, or other controls.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Would it be possible to use SendMessage() to send it to the parent form and then do the calculations at that level instead?

          Comment

          • hype261
            New Member
            • Apr 2010
            • 207

            #6
            Halo,

            Like GaryTexmo mentioned this is a perfect place to use events and delegates to solve your problem. Have your panel create a custom event and delegate and then have your form hook into that event. When ever you catch the 0x84 (WM_NCHITTEST) message just raise the event.

            Comment

            • HaLo2FrEeEk
              Contributor
              • Feb 2007
              • 404

              #7
              Erm...I don't know how to do that. I know I can do Parent.Invoke() , is that what I'm looking for?

              Comment

              • hype261
                New Member
                • Apr 2010
                • 207

                #8
                Halo,

                Here is a tutorial on how to use events and delegates.

                Comment

                Working...