Login
 
Archive
Links
Search
Blog List
There are no categories in this blog.
 
May 22

Written by: Jeremiah Morrill
5/22/2007 5:45 AM 

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?

 

Tags:

4 comment(s) so far...

Re: "Better WPF & WinForm Interop" or "WPF Interop Sucks"

No your not nuts. I was going try and do something like that myself. (Please share your results when you have a chance.) The difficulty is when you want to do the same thing and have the UI of the WinForm (or Win32) content continue to work. My application would be to use interactive Flash content work within a WPF program and have it behave "air space" wise and still have functional interactivity. Grabbing the bitmaps won't be too difficult (I hope), but I'm not sure how I'm going to deal with the interactivity issue yet.

-Eric

By Eric Meyer on   5/23/2007 8:51 AM

Re: "Better WPF & WinForm Interop" or "WPF Interop Sucks"

I my programm ( windev and c#) I would like to have thumbnail of files ( pictures,pdf,word ,html page ) ... how to do ? how to start
thanks
Vincent

By Vincent on   11/24/2007 9:32 AM

Re: "Better WPF & WinForm Interop" or "WPF Interop Sucks"

hey guys!
There is an unfinished project on Codeplex which tries something similar: http://www.codeplex.com/WPFWin32Renderer/Release/ProjectReleases.aspx?ReleaseId=6198

Unfortunately I have not found a complete solution for this. I urgently need a fully fledged web browser control (ideally a control hosting all kinds of ActiveX controls) for WPF, which can be used with a ScaleTransform or a RotateTransform. If anyone has a hint at a working solution (open source or commercial) give me a hint christian_jetter {at} hotmail.com. Thanks!

Chris

By chris on   7/22/2008 1:21 PM

Re: "Better WPF & WinForm Interop" or "WPF Interop Sucks"

I've tried this and it is possible, but it's pretty flakey. There are a couple caveats that I've run into that I can't seem to get past.

1. The WebBrowser control that I was painting in the background would only consume some mouse events. Like I could get scrolling and mouse-move events (hover over), but I can't get mouse-down/up to work.
2. You have to repaint all the time, or else flash and animations on a webpage will not display at all.
3. There's a quarter to half-second lag because of the painting. For instance, a mouse-move event happens and a link gets highlighted, the WebBrowser renders it in GDI+, you copy that HBITMAP to the an Image control which uses DirectX. It takes a small amount of time for it to update. I imagine filling out text forms would be brutal with that kind of lag.

By Brad on   12/17/2008 11:37 AM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
  Minimize
Text/HTML Minimize
Copyright 2007
Downloaded from DNNSkins.com