开发者

Put MFC CDialog in a WPF form

开发者 https://www.devze.com 2022-12-31 03:24 出处:网络
We are porting an MFC application to WPF, and will probably won\'t have time to port the entire applic开发者_开发问答ation. The MFC app has many CDialog-based windows, and we are thinking of leaving s

We are porting an MFC application to WPF, and will probably won't have time to port the entire applic开发者_开发问答ation. 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


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消