简体   繁体   中英

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.

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 .

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++.

IE, 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM