将大型 MFC 应用程序迁移到 WPF/.NET 有哪些技术? [英] What are some techniques for migrating a large MFC application to WPF/.NET?

查看:16
本文介绍了将大型 MFC 应用程序迁移到 WPF/.NET 有哪些技术?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个非常大的遗留 MFC MDI 应用程序.它有大量的 UI 元素 - 可停靠工具栏、自定义树控件、上下文菜单等.它是一个图像处理应用程序,因此主视图使用 DirectX 和 OpenGL 呈现自己.该产品大约有 10 年的历史,这里的首要任务之一是更新它的外观和感觉.

I am currently working on a very large legacy MFC MDI application. It has a large number of UI elements - dockable toolbars, custom tree controls, context menus, etc. It is an image processing application so the main views render themselves using DirectX and OpenGL. The product is about 10 years old and one of the priorities here is to update the look and feel of it.

知道微软在提供 C++/MFC 和 .NET 之间的互操作性方面做得很好,我认为逐步迁移代码库是有意义的.我现在正在努力的是从哪里开始.

Knowing that Microsoft has done a good job of providing interoperability between C++/MFC and .NET I thought it would make sense to migrate the code base incrementally. What I'm struggling with now is where to start.

一种方法是使用 WPF 淘汰 MFC 框架,并尽可能多地重用 C++ 代码.这将使我们能够最大限度地发挥 WPF 架构的优势,但也意味着我们需要很长的开发周期才能再次完全发挥作用.

One approach is to rip out the MFC framework with WPF and reuse as much of the C++ code as we can. This will let us maximize the benefits of the WPF architecture but will mean a long development period until we're fully functional again.

另一种方法是将 MFC 控件一次替换为对应的 WPF 控件.这将使我们能够增量工作.我对这种方法的担忧是,这意味着托管代码和非托管代码之间会有大量的连接点,我不确定从哪里开始替换主菜单和工具栏等内容.

Another approach is to replace MFC controls one at a time with their WPF counterparts. This will allow us to work incrementally. My concern with this approach is that it means there will be an awful lot of connection points between managed and unmanaged code and I'm not sure where to start with replacing things like the main menu and toolbars.

或者我没有看到其他选项?

Or is there another option here I'm not seeing?

任何有关此主题的信息的建议或链接将不胜感激.

Any suggestions or links to information on this topic would be appreciated.

更新:DavidK 提出了一些很好的问题,所以我添加了这背后的动机.

Update: DavidK raised some excellent questions so I'm adding the motivations behind this.

1) 产品的未来发展

此产品仍在积极开发中,并会定期添加新功能.我认为尝试慢慢迁移到 C#/WPF 会很有意义.根据我对 C#/WPF 的有限经验,我发现在 C++/MFC 中工作所带来的生产力提升是惊人的.

This product is still being actively developed with new features getting added on a regular basis. I thought that it would make a lot of sense to try and slowly migrate towards C#/WPF. In my limited experience with C#/WPF I found the productivity gains to be amazing over working in C++/MFC.

我们通过 WPF 获得的另一件大事是利用多头系统的能力.MFC 应用程序仅限于单个顶级框架,因此很难利用多个显示器.

The other big thing we're getting with WPF is the ability to take advantage of multi-head systems. MFC applications are limited to a single top level frame, making it very difficult to leverage multiple monitors.

2) 员工保留和招聘

找到愿意从事 MFC 工作的开发人员变得越来越难.接触新技术对于当前开发人员的职业发展也很重要.

It's getting harder and harder to find developers who are willing to work on MFC. It's also important for the career development of the current developers to get exposure to newer technologies.

推荐答案

重新审视这个,因为我已经成功地用 WPF 替换了我们的顶级 MFC UI(主框架、窗口和工具栏).

Revisiting this because I have successfully replaced our top level MFC UI (the main frame, windows, and toolbars) with WPF.

事实证明,我们的核心绘图代码只需要传递一个 HWND 即可渲染.这使得重用我们现有的大部分 C++ 代码库变得非常容易.

As it turns out, our core drawing code merely needs to be handed an HWND to render into. This made it really easy to reuse the bulk of our existing C++ codebase.

以下是我采用的方法的关键部分的简要概述:

Here's a quick rundown on the key pieces of the approach I took:

  • 使用 .NET HwndHost 类托管一个 HWND 以供 C++ 绘图代码渲染到
  • 为需要向 WPF/C# UI 代码公开的任何本机 C++ 代码创建 C++/CLI 包装器
  • 将大部分 MFC 对话框原样保留在本机 C++ 代码中.这最大限度地减少了完成 UI 所需的工作量.随着时间的推移,MFC 对话框可以迁移到 WPF.
  • Used the .NET HwndHost class to host an HWND for the C++ drawing code to render into
  • Created C++/CLI wrappers for any native C++ code that needed to be exposed to the WPF/C# UI code
  • Left most of the MFC dialogs as-is in the native C++ code. This minimizes the amount of work needed to finish the UI. The MFC dialogs can be migrated to WPF over time.

附带说明一下,我们正在使用 Divelements 的 SandDock 和 SandRibbon,并且非常高兴到现在为止.

As a side note, we're using SandDock and SandRibbon from Divelements and have been very happy with them so far.

这篇关于将大型 MFC 应用程序迁移到 WPF/.NET 有哪些技术?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆