views:

267

answers:

2

I'm working on a C# application with two Windows forms. Both forms are full screen and one form sits on top of the other form as a transparent overlay. The bottom form contains a web browser (also full screen). I'm tracking touch input on the transparent overlay form in order to capture gestures and draw buttons and other controls on the screen. What I need to do is to send all the windows messages that the overlay form gets in its WndProc function to the form below (or the web browser control in the form since that's basically all the lower form is used to contain).

Basically I just need to deal with the gestures on the overlay, all the mouse messages need to still transfer to the web browser to provide certain functionality.

I've tried the naive method of just calling the lower form's WndProc method given the message from the overlay. (And similarly I've tried passing it further to the WndProc of the browser control window). Neither of these methods works. I've also tried simply swapping the HWnd parameter of the Message object to be the handle of the lower form/browser while attempting this and that has also not worked.

So, would anyone be able to think of more methods to try, or possibly the correct method of passing windows messages between forms?

Thanks, Alex

A: 

How about create one master form, and let these two forms be the child forms. Delegate events from the child forms to master, and let master process whatever events you want to process.

KMan
Are you talking about using MDI in some form or just an architecture suggestion? If it's MDI then I've already tried that and MDI child forms can't be transparent, it would seem.If you're talking about architecture then that's already sort of what I'm doing. The overlay form is the master and it has the browser form as an object within it.
Alex
Yes, with MDI you will have no transparency.
volody
Unfortunately transparency is necessary in the overlay form since all it is really for is the provide a pad for touch input to be processed on and the content of the browser below is then manipulated.
Alex
@Alex: Not really MDI; 3 forms can help you create master/child relationship; which really means, to instantiate child objects from within master form. Delegate events of child forms to master; and handle events in master - and may be hide the master form so that you can only see the layered child forms.
KMan
A: 
var topForm = new Form1(); // top form
var browserForm = new Form2(); // bottom form with webbrowser control

add MouseClick event to Form1

private void Form1_MouseClick(object sender, MouseEventArgs e)
{
     browserForm.DoClick(e.X, e.Y);
}

create custom WebBrowserEx control to process mouse click events and add this control to Form2

namespace WindowsFormsApplication1
{
    public class WebBrowserEx: System.Windows.Forms.WebBrowser
    {
        public void DoClick(int x, int y)
        {
            base.OnMouseClick(new MouseEventArgs(MouseButtons.Left, 1, x, y, 0));
        }
    }
}
volody
check How to: Simulate Mouse and Keyboard Events in Codehttp://msdn.microsoft.com/en-us/library/ms171548.aspx
volody