4
votes

I've got a legacy c++ win32 application, and extending it using wpf windows does work.

But what I want to do is have a WPF window as main window, and not just any old window but a prism shell window.

So to my legacy c++ project I want to add a Bootstrapper, shell window, MEF loader, all the bells and whistles. And in there I want to put some commands which open the legacy win32 windows when they are needed.

Now to open WPF windows in a win32 app is simple, I just need to use

System::Windows::Forms::Integration::ElementHost::EnableModelessKeyboardInterop(mywindow);

But how Do I open a win32 window in a WPF app? The win32 window will need a message pump loop, but where do I put this:

MSG  msg;
while (GetMessage(&msg, NULL, NULL, NULL))
{
  TranslateMessage(&msg);
  DispatchMessage(&msg);
}

Can I just create any new thread for the loop? Or is there an interop helper for this, too?

Or is my idea plain insane?

1
Time to flip the switch perhaps. Make a WPF app your main one.Hans Passant

1 Answers

5
votes

Have you seen this?: How WPF uses HWNDs

I also recommend reading this: Walkthrough: Hosting a Win32 Control in WPF

As you will see there is a host window which will contain the control. The host window can also contain self painted content or whatever you want.

You have to override WndProc from HwndHost. May be it is possible to forward to your native handler from that. Have not done that yet.

As @Tergiver pointed out there is no need for a message pump.