Pergunta

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

Foi útil?

Solução

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)

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top