windows MFC的替代品
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4080574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Alternative to MFC
提问by Edward Strange
https://stackoverflow.com/questions/149698/what-is-a-good-mfc-starting-book
https://stackoverflow.com/questions/149698/what-is-a-good-mfc-starting-book
A lot of the upvoted comments claim there are much better alternatives. I'd like to know what they might be.
许多赞成的评论声称有更好的选择。我想知道它们可能是什么。
My main requirement is that the UI use the native widgets so that our automation software can work. Owner drawn windows are much harder to drive.
我的主要要求是 UI 使用本机小部件,以便我们的自动化软件可以工作。业主绘制的窗户更难驾驶。
I'm not particularly liking the design of MFC so an alternative would be good. Only one I've found is WX, which is the one we've already tried and are considering abandoning. We need something that doesn't force us to fight with a bunch of cross-platform wrapping we don't care about. We're writing a Windows application and marketing doesn't give one single crap about targeting Mac or Linux (yeah, it makes my butt hurt too).
我不是特别喜欢 MFC 的设计,所以替代方案会很好。我发现的唯一一个是 WX,这是我们已经尝试过并正在考虑放弃的一个。我们需要一些不会强迫我们与一堆我们不关心的跨平台包装进行斗争的东西。我们正在编写一个 Windows 应用程序,而市场营销并没有针对 Mac 或 Linux 发表任何废话(是的,这也让我的屁股受伤了)。
I've looked at the .NET option a little bit. Problem is I don't know much about it but from what I can tell we'd have to use C# to get a lot of the options readily available with MFC. The C++/CLI toolkit doesn't seem to have docking windows on first glance for instance. In fact, a straight up WinFroms option doesn't seem to either. It looks like we'd have to make a WPF project and that doesn't appear to be at all what we really want (and we'd have a huge bunch of crap to learn besides just another toolkit). Moving out of C++ would also require a lot of wrapping and I don't particularly like the results I've seen from automated wrappers.
我已经稍微研究了 .NET 选项。问题是我对它知之甚少,但据我所知,我们必须使用 C# 来获得许多随 MFC 随时可用的选项。例如,乍一看,C++/CLI 工具包似乎没有停靠窗口。事实上,直接的 WinFroms 选项似乎也没有。看起来我们必须制作一个 WPF 项目,而这似乎根本不是我们真正想要的(除了另一个工具包之外,我们还有很多废话要学习)。离开 C++ 也需要大量的包装,而且我并不特别喜欢我从自动包装器中看到的结果。
The other issue I have with the .NET option is that we've got a pretty drawing intense application (in addition to requiring a lot of forms). I know that you can get similar results with JIT languages like .NET but I also know you've got to be a lot more careful to do so. It's an issue I'd like to avoid worrying about at this time.
我在 .NET 选项中遇到的另一个问题是,我们有一个非常复杂的绘图应用程序(除了需要大量表单之外)。我知道你可以用像 .NET 这样的 JIT 语言得到类似的结果,但我也知道你必须更加小心这样做。这是我目前不想担心的问题。
The other, and probably most important issue with .NET (at least switching languages) is that we've got a huge supply of interface logic that though should be API agnostic, is very much written in C++.
.NET 的另一个,可能也是最重要的问题(至少是切换语言)是,我们有大量的接口逻辑,虽然它们应该与 API 无关,但大部分是用 C++ 编写的。
So what are the other options? Do these people really have points or are they just yelling against anything that isn't their favorite language or toolkit?
那么还有哪些其他选择呢?这些人真的有自己的观点吗,还是他们只是对任何不是他们最喜欢的语言或工具包的东西大喊大叫?
NOTE:
What is the issue here?? I said specifically that porting to other platforms is NOT even remotely a consideration and that I HAVE TO HAVE something that uses the native widget set so we don't have to completely change everything that testing uses to automate the product!!!! Did anyone actually read my question?
注意:
这里有什么问题?我特别说过,移植到其他平台甚至都不是一个考虑因素,我必须有一些使用本机小部件集的东西,所以我们不必完全改变测试用来自动化产品的一切!!!!真的有人读过我的问题吗?
采纳答案by Martin Beckett
Qtis the only real answer for a C++ based gui toolkit at the moment (at least for full desktop apps). Even for purely windows apps it's worth it - it also has excellent integration with visual studio (get the vs-addin) and is very well documented
Qt是目前基于 C++ 的 gui 工具包的唯一真正答案(至少对于完整的桌面应用程序)。即使对于纯粹的 Windows 应用程序,它也是值得的 - 它也与 Visual Studio 有很好的集成(获取 vs-addin)并且有很好的文档记录
wx has some nice points, one being it's very similar to MFC in use, but with Qt going LGPL wx's real advantage has been lost.
wx 有一些优点,其中之一是它在使用中与 MFC 非常相似,但是随着 Qt 的发展,LGPL wx 的真正优势已经丧失。
EditQt widgets aren't native HOWEVER they do use the native styling APIs so that they are indistinguishable from native widgets - if you use the default styles.
编辑Qt 小部件不是原生的,但它们确实使用原生样式 API,因此它们与原生小部件无法区分 - 如果您使用默认样式。
回答by Matt Brunell
Windows forms will work just fine with C++/CLI. Windows forms also happens to be a wrapper around WIN32 handles.
Windows 窗体可以很好地与 C++/CLI 配合使用。Windows 窗体也恰好是 WIN32 句柄的包装器。
There's no difference in the capabilities of C#/Windows Forms compared to C++/Windows Forms. (They just compile differently) Just like you can do the same things with C# and VB.NET...
与 C++/Windows 窗体相比,C#/Windows 窗体的功能没有区别。(它们只是编译不同)就像你可以用 C# 和 VB.NET 做同样的事情......
If you're looking for docking windows, there are a number of third party libraries that do this. (Some are open source, some you can buy.) Because of the CLR, you can directly include assemblies written in a different language.
如果您正在寻找停靠窗口,有许多第三方库可以做到这一点。(有些是开源的,有些您可以购买。)由于 CLR,您可以直接包含用不同语言编写的程序集。
回答by Nick
I'm in roughly the same position: large app, native code, using MFC for the front-end. I don't see any really compelling alternatives, or reasons to switch to anything else.
我的处境大致相同:大型应用程序、本机代码、前端使用 MFC。我没有看到任何真正令人信服的替代方案,或切换到其他任何东西的理由。
That being said, let me offer an opinion. If I were doing a new project, which needed to preserve/inherit a lot of native code, I'd consider trying to do a WPF front-end with a largely native (C++/CLI) main application. This was done with Visual Studio 2010, and it's mostly performant, so it's at least possible. WPF has some UI benefits, and it might be easier to work on and test (from an automation perspective), since it is CLR code. I'm not sure it would be worth the investment and learning curve, but it's the alternative I would consider for a modern pure-Windows application with lots of native code.
话虽如此,让我提出意见。如果我正在做一个需要保留/继承大量本机代码的新项目,我会考虑尝试使用主要是本机 (C++/CLI) 主应用程序来制作 WPF 前端。这是使用 Visual Studio 2010 完成的,并且它主要是高性能的,所以它至少是可能的。WPF 具有一些 UI 优势,并且它可能更易于处理和测试(从自动化角度来看),因为它是 CLR 代码。我不确定它是否值得投资和学习曲线,但这是我会考虑的具有大量本机代码的现代纯 Windows 应用程序的替代方案。
Hope that helps.
希望有帮助。
回答by winwaed
MFC wasn't bad in its day but it is getting a bit old. A good example would be the collections which have been replaced wit the much better STL collections. However you were asking about GUI stuff. There's the WTL (Windows Template Library) which I believe has now been open sourced. Much lighter footprint than MFC but it is designed to work the same way - eg. Most of the classes have the same names and method names.
MFC 在当时还不错,但它有点老了。一个很好的例子是已经用更好的 STL 集合替换的集合。但是你问的是 GUI 的东西。我相信现在已经开源了 WTL(Windows 模板库)。占用空间比 MFC 轻得多,但它的设计方式相同 - 例如。大多数类具有相同的名称和方法名称。
On the downside I've found documentation relative scant and it doesn't seem to work well with the Visual Studio Wizards. This could be my problem though - getting it work with the VS wizards would be quite important IMHO.
不利的一面是,我发现文档相对较少,而且它似乎不适用于 Visual Studio 向导。不过,这可能是我的问题 - 恕我直言,让它与 VS 向导一起工作非常重要。
回答by TheUndeadFish
To offer something I didn't see mentioned in the other answers:
提供我在其他答案中没有提到的东西:
From the sound of it, your only reason for needing native controls is that automation software. And the only reason for needing that automation software to work is for testing. I would assume some series of automated tests are being used to ensure the software works as intended.
从它的声音来看,您需要本机控件的唯一原因是自动化软件。需要该自动化软件工作的唯一原因是为了测试。我假设正在使用一系列自动化测试来确保软件按预期工作。
If that's the case, then here is something to consider: There is a reasonably popular design pattern in the C#/WPF realm called Model-View-ViewModel. Without getting into excessive detail here, the basic idea is that you can separate the actual GUI controls (the View) from the code that handles how those controls interact with the rest of the business logic in the application. That code is the so-called ViewModel. Among other things, this lends itself to designs where that ViewModel (and all the rest logic of the application) can be tested through typical unit-testing methods without actually needing GUI controls to be present.
如果是这种情况,那么需要考虑以下几点:C#/WPF 领域中有一种相当流行的设计模式,称为 Model-View-ViewModel。此处无需过多赘述,基本思想是您可以将实际的 GUI 控件(视图)与处理这些控件如何与应用程序中的其余业务逻辑交互的代码分开。该代码就是所谓的 ViewModel。除此之外,这适用于可以通过典型的单元测试方法测试 ViewModel(以及应用程序的所有其余逻辑)的设计,而实际上不需要存在 GUI 控件。
So whatever testing the automation software is used for could potentially be replaced by straight unit-testing code.
因此,无论自动化软件用于什么测试,都可能被直接的单元测试代码所取代。
However, my own experience in this realm is not nearly as extensive as I would like. So if you consider this at all, I strongly suggest further research. As a start, googling terms like "Model-View-ViewModel" and "MVVM" should eventually yield some more detailed discussions about that part.
然而,我自己在这个领域的经验远没有我想要的那么广泛。因此,如果您完全考虑这一点,我强烈建议进一步研究。首先,像“Model-View-ViewModel”和“MVVM”这样的谷歌搜索术语最终应该会产生关于该部分的更详细的讨论。
回答by Puppy
I've seen Qt used fairly extensively. I personally have not used Qt, but I see a lot of questions about it, far more than wXwidgets or MFC. I'd start with that.
我已经看到 Qt 的使用相当广泛。我个人没有用过Qt,但是看到很多关于它的问题,远不止wXwidgets或者MFC。我会从那个开始。