Win32 windows hosting in a WPF application?

I have a legacy C ++ win32 application and its extension using wpf windows works.

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

So, to my C ++ project for old projects, I want to add Bootstrapper, shell window, MEF loader, all bells and whistles. And there I want to put some commands that open old win32 windows when they are needed.

Now, to open WPF windows in a win32 application, you just need to use

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

But how to open win32 window in WPF application? The win32 window will require a message pump circuit, but where can I put this:

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

Is it possible to create a new thread for a loop? Or is there an assistant for this too?

Or is my idea crazy?

+4
source share
1 answer

Have you seen this ?: How WPF uses HWND

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

As you will see, there is a host window that will contain the control. The host window may also contain self-configuring content or whatever.

You need to override WndProc from HwndHost. Perhaps this can be redirected to your own handler. Have not done it yet.

As @Tergiver noted, there is no need for a message pump.

+5
source

All Articles