10

I am developing an application that needs to a host native Win32 window and somehow i have no clues how to do that.

I need to create a WPF dialog window that could display native Win32 control on it. This dialog window will have WPF controls on it as well, so i am looking for some sort of Grid that i could take HWND of and send it to the unmanaged C++ control, so it could draw on it. Is that possible ?

I don't need to know what happens within that surface, just need to let C++ dll to draw on it and all i need to do is to pass HWND that has proper size (which i know).

I am kinda new to WPF (used to do win32 programming) and quite lost (but i now how to interface it to C# .NET etc)

Would be great if you could send me any hints :)

DLRdave
  • 13,876
  • 4
  • 53
  • 70
pablox
  • 643
  • 2
  • 8
  • 17

1 Answers1

13

you can start by following the instructions/steps here: Hosting Win32 Content in WPF

from the article introduction:

A Walkthrough of Win32 Inside Windows Presentation Framework (HwndHost)

To reuse Win32 content inside WPF applications, use HwndHost, which is a control that makes HWNDs look like WPF content. Like HwndSource, HwndHost is straightforward to use: derive from HwndHost and implement BuildWindowCore and DestroyWindowCore methods, then instantiate your HwndHost derived class and place it inside your WPF application.

If your Win32 logic is already packaged as a control, then your BuildWindowCore implementation is little more than a call to CreateWindow.

then if you have a specific issue ask here in SO and people will help you on specific points.

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • That was exactly what i've been looking for :) I have my dialog window up and running now. Many thanks! – pablox Sep 21 '11 at 01:40
  • Can I use `HwndHost` to host in a typical Windows Forms app? –  Feb 19 '14 at 06:36
  • @Desolator, yes, as [WindowsFormsHost](http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost%28v=vs.110%29.aspx) inherits from HwndHost. – Justin R. May 06 '14 at 17:56