Search code examples
c#winformswpf-controlspinvokewinforms-interop

C# - natively create a form window as a child to an existing window


I have a C# (4.72) library that creates a window using native API’s (pinvoke). I inserted this window into an existing application successfully. So, I have a child window inserted into the existing application, and all works fine. Now I want to create a C# form as a child for that window.

I desire to create a form and set that form as a child to the previous window I inserted into that application. I have a control (WPF) that I want to insert into the form and set properties. But before starting down the xaml control path, I want to create the form and set the parent as the inserted window.

My old application was C++, and I inserted an MFC child dialog with an old control. But I have a new spec to create a modern WPF user control.

Does anybody have any suggestions?

I would really appreciate any help or suggestions that anybody might have.


Solution

  • I wrapped the WPF control in a library and integrated that into winform. I am using the winform as a child to my custom window. I used pinvoke to set the parent. I defined an interface to capture all the events and integrated into my main application. It was a lot of work, but I got everything playing together nicely.