承载WPF窗口并在MFC应用程序中使用其控件 [英] Hosting WPF window and using its controls in MFC Application

查看:226
本文介绍了承载WPF窗口并在MFC应用程序中使用其控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

感谢您的文章.

我遇到一种情况,我必须从我的MFC应用程序访问WPF窗口及其控件.能够显示WPF窗口并指向它(cwnd)指针,但无法访问其中的控件,如列表视图,列表框,单选按钮,复选框等.我没有WPF窗口的源代码. br/>
所以,请您能帮助我解决这个问题.我为此尝试了解决方案,但发现的方法相反(在WPF窗口中托管MFC).

HI ,

Thanks for the Article.

I have come across a situation where, i have to access a WPF window and its controls from my MFC application. Am able to display the WPF window and get (cwnd)pointer to it but am not able to access the controls in it like list view, listbox, radio buttons, check boxes etc. I dont have the source code for the WPF window.

So, can you people please help me out in this concern. I tried solution''s for this but i found in reverse way (Hosting MFC in WPF window).

推荐答案

请参阅我的评论.我从来没有尝试过这样做,但是我非常确定:如果您设法在MFC应用程序中显示WPF窗口,那么其他所有内容都可以解决.您需要有一个用C ++/CLI编写的混合模式(托管+非托管)项目.它可以托管托管代码和非托管代码,并调用托管"ref"类型和非托管函数的托管方法/属性.无论如何,这不容易.

我的想法是:如果您成功嵌入了WPF这样强大的思想,那么您实际上并不需要像MFC这样古老,笨拙的用法以及通常有问题的东西.我建议只有一个UI,仅WPF.同时,您可以从现有应用程序代码中借用所有非UI C ++代码. (如果您询问有关使用MFC的信息,听起来好像您已经有一个使用MFC用C ++编写的旧版应用程序;为什么还要问这个问题?)

如果在您的旧版代码中,UI与其余代码完全分开,则此方法可以很好地工作.对于太多的开发团队而言,无论使用什么平台,这都是一个主要问题.在这种情况下,这种情况的所有解决方案都非常困难.在很多情况下,仅重写UI是可行的.而且,很可惜,许多开发人员都为时已晚.无论如何,如果您决定将应用程序迁移到任何平台或框架,则主要的关注点不应是从一个框架迁移到另一个框架,而是要从牢固耦合的UI迁移到松散耦合.请参阅:
http://en.wikipedia.org/wiki/Loose_coupling [ http://en.wikipedia.org/wiki/Separation_of_concerns [
Please see my comment. I never tried doing such things, but I''m pretty much sure: if you managed to show a WPF window in your MFC application, everything else is solvable. You need to have a mixed-mode (managed+unmanaged) project written in C++/CLI. It could host both managed and unmanaged code and call both managed methods/properties of managed "ref" types and unmanaged functions. This cannot be easy in this case, anyway.

Here is what I think: if you managed to embed such a powerful think as WPF, you don''t really need such old, awkward in usage and generally problematic thing as MFC. I would advise to have only one UI, WPF only. At the same time, you can have all non-UI C++ code borrowed from your existing application code. (If you ask about using MFC, it sounds like you already have a legacy application written in C++ with MFC; why else would you ask this question?)

This can work well if in your legacy code UI is well separated from the rest of the code. For too many development teams, this is a major problem, no matter what platform is used. In this case, all the resolutions of this situation are quite difficult. There are many cases when only re-writing the UI is practical; and, too bad, many developers understand it too late. Any way, if you decide to migrate the application to any platform or framework, your primary concern should be not migrating from one framework to another, but moving from strong coupled UI to loose coupling. Please see:
http://en.wikipedia.org/wiki/Loose_coupling[^];

More general view on software development and coupling:
http://en.wikipedia.org/wiki/Separation_of_concerns[^].

—SA


这篇关于承载WPF窗口并在MFC应用程序中使用其控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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