Constantin
Constantin

Reputation: 28154

Adding WPF window to Win32 application

I have a monster of a win32 application with GUI based on a mixture of MFC, WTL, user32 and a few other technologies. I need to add another top-level window and I would like to give WPF a chance.

Could you help me identify the steps necessary to host a WPF window in win32 app? Details are welcome.

Upvotes: 1

Views: 1587

Answers (2)

Cechner
Cechner

Reputation: 859

Keep in mind if its a top-level window you're after (and not a window embedded within another window) you can simply create a new Window-derived WPF window from managed C++.

I.E., either 1) create a C++/CLI library that references your WPF library and call that from your unmanaged code or 2) add the /clr library setting (not recommended, due to performance implications) and add a reference to your WPF library. Then simply call:

#include <vcclr.h>

gcroot<MyWindow^> newWin = gcnew MyWindow();
newWin->Show();

Upvotes: 0

Anvaka
Anvaka

Reputation: 15823

I'm sorry for giving trite answer, but I can't explain it better than it is explained at MSDN: Hosting WPF Content in a Microsoft Win32 Window, Walkthrough: Hosting a WPF Clock in Win32. You may also be interested in WPF Documentation samples at MSDN Code Gallery, or alternatively look at their mind-mapped version.

Upvotes: 1

Related Questions