2

From MSDN article I found out that WinForm controls can be hosted in a WPF application using HwndHost.

Also, from other internet resources, I found that WPF is rendered using DirectX and WinForm is rendered using GDI+.

My question is, what renders a WinForm control when the WinForm control is drawn in a WPF application; DirectX, GDI+, or both?

I have very little experience with both technologies and making baby steps.

Thank you

Community
  • 1
  • 1
Alok
  • 46
  • 4

2 Answers2

1

You are incorrect about requiring a HwndHost to display a Windows Forms control in a WPF Application. The article that you were reading is for Win32 Interoperation, not for Windows Forms. To use a Windows Forms control in a WPF Application, you should use the WindowsFormsHost Class.

As for what will render the Windows Forms control, you need to understand something. WPF uses a totally different graphics system to Windows Forms. From the WPF Graphics Rendering Overview page on MSDN:

One of the keys to understanding the role of the Visual object is to understand the difference between immediate mode and retained mode graphics systems. A standard Win32 application based on GDI or GDI+ uses an immediate mode graphics system. This means that the application is responsible for repainting the portion of the client area that is invalidated, due to an action such as a window being resized, or an object changing its visual appearance.

In contrast, WPF uses a retained mode system. This means application objects that have a visual appearance define a set of serialized drawing data. Once the drawing data is defined, the system is responsible thereafter for responding to all repaint requests for rendering the application objects. Even at run time, you can modify or create application objects, and still rely on the system for responding to paint requests. The power in a retained mode graphics system is that drawing information is always persisted in a serialized state by the application, but rendering responsibility left to the system.

Therefore in general, the WPF Rendering system will render the WindowsFormsHost, although you may find that Windows Forms does actually perform some rendering of its own on the Windows Forms control.

Community
  • 1
  • 1
Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • @Sherian: Element Host [Class] is a WPF control that is used to host a WPF element in a Windows Form App. Windows Form Host is a WPF control that is used to host a Windows Form element in a WPF App. [http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost%28v=vs.110%29.aspx] [http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost%28v=vs.110%29.aspx] – Alok Jul 08 '14 at 10:04
  • Thanks... you're quite right. I've updated my answer accordingly. – Sheridan Jul 08 '14 at 10:10
0

You need to understand WPF and Win32 Interoperation, it show how controls are plotted.

On the other hand Technology Regions Overview explains the relationship between Wind32, WPF and DirectX.

Hope it will make you more clear about this..!!!

H. Mahida
  • 2,356
  • 1
  • 12
  • 23