Win32 API与MFC:选择什么 [英] Win32 API vs MFC : What to choose

查看:127
本文介绍了Win32 API与MFC:选择什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近研究过Win32 API。 (买了Charles Petzold的书,几乎完全读了它)。我真的很喜欢Win32 API,但感觉我在浪费时间。所以我在考虑学习MFC。我相信我能够快速学习,因为我知道Win32。



有几个问题。

是否值得学习MFC?

将MFC应用程序移植到其他平台有多难/简单?

你个人喜欢什么? MFC或Win32(或两者都没有)?



编辑:

我只用C ++编写本机应用程序。

解决方案

总是存在低级别的东西和非常高级别的东西以及两者之间的逐渐过渡。在Windows上,如果我们谈到GUI,最低级别是WinAPI,它是一个过程C接口(主要位于用户和gdi库中),并且一个非常好的高级gui框架实现的接口通常是面向对象的,它通常没有与Windows的纯C WinAPI gui接口有关。



高级框架(如Qt,java swing,Delphi,.Net gui框架)似乎可能是如果您习惯使用winapi或MFC但在学习它们之后(以及它们使用的MVC模式),最初很难使用这些更高级别的框架要好得多,并且用它们编写更好/可重复使用的代码更容易。更不用说大多数优秀的高级库为您提供了可视化编辑窗口的工具(以比winapi和mfc中使用的winapi对话框资源编辑器更好的方式)。高级API通常会完全隐藏低级API(简单/普通的gui代码不包含丑陋的东西,比如挂钩到带有MFC对象的winapi HWNDS /对话框控件)。



如果你专注于漂亮的代码设计,那么学习一个高级的面向对象的gui库是如何工作的。如果你对引擎盖下的内容感兴趣,那么也要学习一些低级别的winapi,它肯定会让你成为一个更好的程序员,你就会理解更高级别的gui库,特别是如果你学会了如何实现一个简单的面向对象的gui框架。 WINAPI。在我看来,在Charlest Petzold的书中挣扎并不是浪费时间。



MFC:忘记它并且只在必要的时候学习它。 BTW MFC是一个非常大的库,不仅仅是关于gui: http://msdn.microsoft.com /en-us/library/ws8s10w4.aspx [ ^ ]

MFC包含一些有用的高级类(例如做网络,......)但是使用这些类会使你的程序很难移植到其他平台。如果我们谈到MFC的GUI部分:它更接近原始的winapi,然后是高级面向对象的漂亮框架。事实上,如果因为巨大的遗产代码,MFC已经过时且MS维持,但它与现代gui框架没什么关系,并且它的大多数类方法与winapi函数具有相同的名称,并且通常它们也是如此。大多数MFC机制建立在原始的winapi机制上,而MFC并没有试图隐藏它(在我看来这有时很糟糕)。 MFC只有一半(或者可能是三分之一)面向对象,其余的基本上是直接的winapi。如果你还想学习MFC(或者你必须学习MFC,因为你必须在MFC中维护一些项目),那么学习Charles Petzold的书是必须的,你必须知道winapi以便与MFC合作,因为MFC gui基本上是一组具有与winapi的gui部分相同的方法的类。期。如果你对平庸的MFC知识没问题那么你可以在不学习winapi的情况下通过网络上的复制粘贴示例来实现它,但是如果遇到一些棘手的问题,你通常需要其他人的帮助。



如果你想尝试一些不错的gui框架,那么搜索一些用上面提到的gui框架编写的gui示例代码,并将它们与mfc示例进行比较。查看面向对象的级别以及与winapi或这些框架和MFC的任何其他低级api的连接。你会看到差异,特别是如果你有winapi经验。



MFC的开源和跨平台兄弟是wxWidgets,对我而言wxWidget解决方案/机制感觉非常类似于MFC。



编辑:忘了提一些重要的东西:

Qt非常好,我唯一不喜欢它是编译前的超级信号槽机制及其代码生成器。但是lib本身还算可以。 Qt还有很多非gui帮助类(比如网络,xml,......)。



另一个非常好的选择是C ++ Builder。它的gui编辑器就像Delphi或.Nets gui构建器一样,在我看来是最好的。 C ++ Builder的缺点是你必须坚持使用它的C ++编译器,但如果可以,那么这个gui构建器可能是用于C ++ gui编辑的最好的RAD工具。如果您对使用最好的gui开发工具开发gui密集型应用程序感觉很好,那么一定要尝试.Net,Delphi(pascal)或C ++ Builder(与Delphi完全相同的IDE)。


这取决于你期望在不久的将来做什么样的工作;这些领域正在使用什么样的技术(查看工作列表)。



一个重要的事情是,在开发应用程序时要拆分GUI组件(MFC, QT,...)来自核心功能(C ++),因此如果您需要移植应用程序,您将只需要移植/重写GUI部分而不是核心功能。



过去12年我一直在使用C ++ / MFC全职,我知道如果我换工作,我可能需要做一些其他工作(C ++ /本地没有工作MFC),


如果你想要C ++和Windows,你可以选择MFC。在其他平台上它不会运行。



如果你想要便携性,你最好学习Java。



我编程超过10年的MFC但是觉得它正在消失。我使用MFC作为GUI-Stuff并使用C ++进行艰苦的工作。



我的提示不是学习MFC而是使用边做边学 接近所需的MFC-Stuff。在codeproject中有大量的MFC代码,所以你可以在这里学习它。 ; - )

I have recently studied the Win32 API. (Bought Charles Petzold's Book and almost completely read it). I really like the Win32 API but it feels like I'm wasting time. So I am thinking about learning MFC. I believe I will be able to learn fast since I know Win32.

There're a few questions.
Is it worth learning MFC ?
How hard/easy is it to port MFC applications to other platforms ?
What do you personally prefer; MFC or Win32 (or neither) ?

Edit:
I am only writing native apps with C++.

解决方案

There is always low level stuff and very high level stuff and a gradual transition between the two. On windows if we speak of GUI the lowest level is the WinAPI that is a procedural C interface (located mostly in the user and gdi libraries) and the interface of a really good high level gui framework implementation is usually object oriented and it has usually nothing to do with the pure C WinAPI gui interface of windows.

A high level framework (like Qt, java swing, Delphi, .Net gui frameworks) may seem to be hard to use at first if you are used to using winapi or MFC but after learning them (and the MVC pattern they make use of) these higher level frameworks are much better and its much easier to write nicer/reusable code with them. Not to mention that most good high level libs give you tools to visually edit the windows (in a much better way then the winapi dialog resource editor used in winapi and mfc). The high level APIs usually hide the low level API completely from you (and simply/normal gui code doesnt contain ugly stuff like hooking into winapi HWNDS/dialog controls with MFC objects).

If you focus on nice code design then learn how a high level object oriented gui library works. If you are interested about whats going on under the hood then learn some low level winapi too, it definitely makes you a better programmer and you understand even higher level gui libraries especially if you learn how to implement a simple object oriented gui framework on top of winapi. In my opinion struggling through the book of Charlest Petzold isn't a waste of time.

MFC: forget about it and learn it only if it is necessary. BTW MFC is a very big library that isn't only about gui: http://msdn.microsoft.com/en-us/library/ws8s10w4.aspx[^]
MFC contains some useful high level classes (for example to do networking, ...) but using these makes your program very hard to port to other platforms. If we speak of the GUI part of MFC: it is much more near to the raw winapi then to a high level object oriented nice framework. In fact, MFC is quite outdated and MS maintains if because of the tremendous heritage code but it has not much to do with a modern gui framework and most of its class methods has the same name as the winapi functions and usually they do the same. Most of the MFC mechanisms build on the raw winapi mechanisms and MFC doesnt try to hide this (that is sometimes terrible in my opinion). MFC is only half (or maybe one-third) object oriented and the rest is basically straight winapi. If you still want to learn MFC (or if you have to learn MFC because you have to maintain some projects in MFC) then learning the book of Charles Petzold is a must, you have to know winapi in order to work with MFC because MFC gui is basically a set of classes that have the same methods as the gui part of the winapi. period. If you are OK with mediocre MFC knowledge then you can do it without learning winapi just by copy pasting examples from the net but in case of some tricky problems you will often need the help of others.

If you want to taste some nice gui frameworks then search for some gui example code written in the above mentioned gui frameworks and compare them with mfc examples. Check out the level of "object orientedness" and the connection with winapi or any other low level apis of these frameworks and MFC. You will see the difference especially if you have winapi experience.

The opensource and crossplatform sibling of MFC is wxWidgets, to me wxWidget solutions/mechanisms feel quite similar to those of MFC.

EDIT: Forgot to mention some important things:
Qt is quite good, the only thing I don't like in it is the superflous signal-slot mechanism and its code generator before compilation. But the lib itself is quite OK. Qt also has a lot of non-gui helper classes (like networking, xml, ...)

Another very nice alternative is C++ Builder. Its gui editor is like that of Delphi's or .Nets gui builder that is the best in my opinion. C++ Builder has the disadvantage that you have to stuck to its C++ compiler but if that is OK then this gui builder is probably the best RAD tool for C++ gui editing. If you are curious about how does it feel to develop gui-intensive app with the best gui development tools then definitely try either .Net, Delphi (pascal) or C++ Builder (that has exactly the same IDE as Delphi).


It depends on what kind of work you expect to do in the near future; and what kind of technology those domains are using (look at the job listings).

One important thing is that when developing application is to split the GUI compoenents (MFC, QT, ... ) from the core features (C++) so that if you need to port the application, you will have to only port/rewrite the GUI part and not the core features.

I've been using C++/MFC full time for the last 12 years, and I know that if I change job, I will probably need to do something else (there ain't no job locally with C++/MFC),


MFC is your choice if you want C++ and Windows. On other platforms it wont run.

If you want portability you better learn Java.

I am programming for over 10 years MFC but feel it is disappearing. I use the MFC for "GUI-Stuff" and do the hard work with C++.

My tip is not "to learn" MFC but use the "learning by doing" approach for the needed MFC-Stuff. In codeproject are tons of MFC-code so you can learn it here. ;-)


这篇关于Win32 API与MFC:选择什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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