views:

559

answers:

1

I tried to derive a class form ElementHost and overiding the CreateParams method:

    protected override CreateParams CreateParams
    {
        get
        {
            const int WS_EX_TRANSPARENT = 0x20;
            CreateParams cp = base.CreateParams;
            cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT;
            return cp;
        }
    }

This makes it transparent, but the form is not clickable.

+1  A: 

Try adding this to your derived class:

private const int WM_NCHITTEST             = 0x0084;
private const int HTTRANSPARENT            = (-1);

protected override void WndProc(ref Message m)
{
   if (m.Msg == WM_NCHITTEST)
   {
      m.Result = (IntPtr) HTTRANSPARENT;
   }
   else
   {
      base.WndProc(ref m);
   }
}

This should make the entire ElementHost "transparent" to the mouse, if you want the WPF content to respond to the mouse you will have to use VisualTreeHelper.HitTest to decide what to return from your WM_NCHITTEST handler.

I haven't tested it with ElementHost but it works with normal WinForms controls.

Nir
Given that this answer is accepted, does that mean the OP managed to get it to work? I've tried the same thing in my own app, but the WPF controls don't appear until hovered over and the WinForms controls underneath never receive any mouse input (although they are visible).
Mal Ross