MFC Dll将集成到WPF应用程序中 [英] MFC Dll to be integrated into WPF application

查看:81
本文介绍了MFC Dll将集成到WPF应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一个基于MDI的相当大的应用程序,该应用程序具有插件Architecture.
插件MFC非托管DLL带来了许多非托管对话框(CDialog基本调用).
我计划最初仅在WPF中构建主GUI框架,并将插件保持在MFC中,并具有Managed wrapper dll,使我可以在托管应用程序中调用此对话框.

在一段时间内慢慢更改100个以上的插件.

我想有一个新的应用程序以及一个具有对接支持的MDI.因此,我计划使用ActiPro和Syncfusion中的第三部分库.

我的问题是

1)如何根据加载的插件的需要在WPF应用程序中添加/删除菜单项?

2)如何将MFC对话框停靠在WPF应用程序中,就好像它们是使用WPF创建的一样.

任何帮助将不胜感激.

Shashi

Hello

I have a MDI based rather huge application that has plugin Architecture.
The plugins MFC unmanaged DLLs that bring many unmanaged dialog(CDialog base calls).
I am planning to initially only build the main GUI framework in WPF and keep the plug ins still in MFC, and have Managed wrapper dll which enables me to call this dialog in a managed application.

Slowly change 100+ plugin we have over the period of time.

I would like to have new application also a MDI with docking support. So I am planning to use 3rd part libraries from ActiPro and Syncfusion.

My question is

1) How can I add / remove menu items in a WPF application based on the need of the plug in that is loaded ?

2) How will I able to dock my MFC Dialogs in a WPF application as if they were created using WPF.

Any help is greatly appreciated.

Shashi

推荐答案

这是一次令人不愉快的突破性练习,很少使用,所以我建议您务必避免这样做.结果将是丑陋的,绝对不可携带的并且很难维护.

首先,无法在WPF宿主控件中插入MFC窗口控件.通常,WPF与Windows几乎无关. WPF控件不是Windows,很少被排除.

因此,首先需要将WPF与System.Windows.Forms集成在一起,后者可以提供用于托管某些外部Windows的控件.因此,您需要使用WPF到System.Windows.Forms互操作层.阅读演练:在WPF中托管Windows窗体控件: http://msdn. microsoft.com/en-us/library/ms751761.aspx [ ^ ].解决方案是使用System.Windows.Forms.Integration.WindowsFormsHost,请参见 http://msdn. microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx [ http://msdn.microsoft.com/en-us/library /ms633541%28v=vs.85%29.aspx [ ^ ].您将需要调整MFC窗口样式,使其像面板的子窗口一样表现良好.一个问题是,从.NET的角度来看,面板无法知道它是某个外部窗口的父级.

当您拥有所有这些内容时,就可以更改为同时使用WPF,System.Windows.Forms和MFC来构建怪物.不要以为这会对您有很大帮助.最大的问题是MFC.如何组织本机MFC代码和.NET之间的互操作?唯一的方法是P/Invoke;而且你不能通过任何课程.基本上,您只能使用.NET和非托管代码之间常见的原始类型P/Invoke静态函数.在此级别上,组织UI开发通常需要的组件之间的复杂协作非常困难.

现在,停靠MDI".从MDI的严格意义上讲,没有对接支持或类似的支持.这是您不太了解的一些过时且不鼓励使用的UI设计.另外,WPF不支持MDI(感谢您:-)).

通过"MDI",您可能意味着别的意思-具有多个停靠容器的现代界面(它们都不是Windows或控件).您可以尝试AvalonDock;请参见 http://avalondock.codeplex.com/ [ ^ ].

总体而言,我认为此活动没有任何意义.很有可能,您可以在不使用.NET 的情况下将MFC应用程序升级到新的需求,并且编写一个全新的.NET应用程序可以比进行集成"所需的精力和开发时间更少.项目.我不确定您是否会完全完成这样的项目.

认真考虑,如果可以避免的话.

—SA
This would be so unpleasant head-breaking exercise with so little use so I would advise you to avoid it by all means. The result would be ugly, absolutely non-portable and very hard to maintain.

First, there is not way to insert a MFC windowed control in a WPF host control. Generally, WPF has almost nothing to do with windows. WPF controls are not windows, with rare exclusion.

So, first you need to integrate WPF with System.Windows.Forms which can provide controls for hosting some external Windows. So, you need to use WPF to System.Windows.Forms interoperation layer. Read Walkthrough: Hosting a Windows Forms Control in WPF: http://msdn.microsoft.com/en-us/library/ms751761.aspx[^]. The solution is to use System.Windows.Forms.Integration.WindowsFormsHost, see http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx[^].

Now, you can insert some System.Windows.Forms control, such as Panel, in WPF window. When you do it, you can PInvoke Windows API SetParent using the panel handle and the handle of you MCF window. See http://msdn.microsoft.com/en-us/library/ms633541%28v=vs.85%29.aspx[^]. You will need to adjust MFC window styles the way it behaves nicely as a child window of the panel. One problem is that the panel cannot know that it is a parent of some external window, from .NET standpoint.

When you have all that, you have a change to build a monster using WPF, System.Windows.Forms and MFC at the same time. Don''t think it will help you much. The biggest problem is MFC. How to organize interoperation between native MFC code and .NET? The only way is P/Invoke; and you cannot pass any classes. Basically, you can only P/Invoke static functions with primitive types common between .NET and unmanaged code. On this level, it is extremely difficult to organize complex cooperation between component which is usually required by UI development.

Now, "docking MDI". In a strict sense of MDI, there is no docking support or anything like that. This is some old and discouraged UI design which you don''t really know. Also, MDI is not supported by WPF (thanks goodness :-)).

By "MDI" you probably mean something else — modern interface with multiple docking containers (none of them are windows or controls). You can try AvalonDock; see http://avalondock.codeplex.com/[^].

Overall, I don''t see any sense in this activity. Chances are, you can upgrade your MFC application to your new requirement without using .NET and write a brand new .NET application doing the same using less effort and development time than you would take for your "integration" project. I''m not sure you will complete such project at all.

Seriously, think if you can avoid it.

—SA


这篇关于MFC Dll将集成到WPF应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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