Possible better approach to WPF/Winform Interop?
I'm sure if you have done any WPF interop (Winforms in WPF), you might have noticed how easy it is to make it work. But right after you make it work, you quickly find out how difficult it is to make it look and act decent. You probably noticed your archaic WinForms control defies all z-order laws and steals the entire "air space" of your WPF window. It's like a huge, ugly insect splattered on your wind-shield, and you haven't any fluid left to wipe it off.
What if I want to texture a Webbrowser control on a WPF 3D Mesh? What if I want to animate and composite my old WinForms control? What if I want my cake and to eat it too? I came up with an obvious solution, so obvious, I'm sure someone out there has thought of it also.
What if we were to capture the Winforms content to a bitmap using the WM_PRINT Win32 message (Control.DrawToBitmap() doesn't seem as good). Then take that bitmap and put it on to a WPF Image. For the user to interact with the control, WndProc messages could be routed to the hidden Winforms control. I know capturing HWNDs to an hDC isn't the most efficient method, but in a scenario with a small control that doesn't need a lot of painting, it would be most desirable. This method could also be greatly sped up by using the native bitmap buffer pointer hack I posted on earlier.
I did a small bit of testing with the Webbrowser Winforms control and some p/invoke to get the bitmap of the control. I then took the bitmap and simply applied it to a XAML Image. Once in bitmap state we really have the freedom to do whatever our WPF heart's desire with it.
So what do you guys think? Am I nuts? Is this a pipe-dream?