views:

187

answers:

2

Hi,
We are porting an MFC application to WPF, and will probably won't have time to port the entire application. The MFC app has many CDialog-based windows, and we are thinking of leaving some of these windows in MFC, and show them inside a WPF window, so we can control their modality from WPF.

Is there an easy way to accomplish that? If not, can you recommend another way to handle this?

thanks,
splintor

A: 

If you are using standard common dialogs, then just use the wpf equivalents, otherwise you might have to make them from scratch in wpf. Or use a Windows Forms host control that displays the dialog inside the wpf window.

Rick Ratayczak
But how do I do that? How do I put a CDialog inside a WPF window? That was my question...
splintor
I don't know anything about MFC, but you could export a C++ function that will show the dialog, but that won't be in the wpf window. That would be in it's own window.
Rick Ratayczak
But you are better off making a similar dialog on WPF from a code maintenance point of view.
Rick Ratayczak
I know porting it to WPF would be better, but I'm not sure we will have time to it. I wanted to know if there is an easy way to display the MFC CDialog *inside* the WPF window.
splintor
Yeah, I do not know of a way directly using the dialog in a wpf window. But if you need help converting stuff, let me know. rickrat at gmail
Rick Ratayczak
See this: http://msdn.microsoft.com/en-us/library/aa969773.aspx
Rick Ratayczak
+2  A: 

I looked into this a while back for a similar legacy application, I started with WPF and Win32 Interoperation Overview together with host MFC class inherited from CWnd in WPF. Refer to (and search for) HwndHost Class, together with Hosting a Simple Win32 Control in a WPF Application.

The trouble was that it never worked well - I felt it compromised the WPF application and I couldn't get it to work anywhere near reliably enough so I gave up on this approach.

So, taking a different tack I rebuilt the MFC application as a standalone 'dialog provider' which just had all of the dialogs. This just did all of the dialog work and notified the WPF application of the results. This worked and enabled the application to move forwards. I did also try Leveraging the .NET Framework Inside an MFC Application but it didn't work initially and time was of the essence.

The final outcome was a Q&D converter written in AWK that took the .rc the .cpp and the .h and produced the XAML & C# for each dialog in a form ready for editting. If you've built your MFC dialogs using class wizard then there should be helpful delimiters which were very useful in this process.

Example helpful delimiter:

//{{AFX_DATA_INIT(CDialogFileProperties)
Richard Harrison