学习MFC编程的先决条件 [英] Prerequisites for learning MFC programming

查看:75
本文介绍了学习MFC编程的先决条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道一些C ++和C,并且我现在使用的项目是很多MFC编程.有经验的人可以告诉我学习MFC的先决条件.

此外,什么是最好的学习资源?

任何特定的书籍或视频系列?

我知道这个问题太笼统了,但是答案可能对我(或任何其他研究MFC的人)有很大帮助

谢谢!

解决方案

+1好问题!

tl; dr :按此顺序学习Win32.

到目前为止,MFC最重要的前提条件是对 Windows API (也有时称为 Win32 API ).您还需要熟悉C ++的一些关键概念并熟悉这些工具.我建议的先决条件清单是:

  1. 在Windows API开发方面有扎实的背景.
  2. 熟悉C ++的相关概念.
  3. 了解工具.

以下是这些步骤的摘要,以及指向其他信息的链接.

1. Windows API:

Windows API通过C接口公开所有服务.结果,资源管理通常是乏味的样板代码.并在源代码中可见(有时在阅读代码时获得不可思议的好处). MFC在很大程度上是围绕Windows API的自动化资源管理包装器(和实用程序库),隐藏了大多数资源管理和类型转换.要熟练使用MFC,您必须了解它的隐藏内容.

要开始使用Windows API,您需要做的就是简要介绍主要组件,我建议 theForger的Win32 API教程(由伪造 noreferrer>#winprog 名声).它涵盖了消息处理窗口控件 GDI ,并奠定了坚实的基础.如果您想花时间(花很多时间)来更详细地研究Windows API,那么迄今为止最好的资源可能仍然是Charles Petzold的托管的Petzold ). MSDN还是获取特定领域的概述和详细文档的好资源,例如:

2. C ++关键概念:

MFC是根据C ++实现的.虽然它早于正式的C ++标准,但您在那儿不会发现太多时髦的事情.很少的模板代码,当然也没有新的C ++ 11功能.与基本C ++概念的亲密关系将使您走得很长.

如前所述,MFC在很大程度上是围绕Windows API的资源管理包装.通常,Windows API资源和MFC对象之间存在直接映射(例如 CWnd HDC : CMap ),您自然会接触到模板.那里没有什么涉及,只是非常基本的类型参数化,以重用容器代码并启用类型安全的元素访问.可以在以下位置找到MFC容器的简介:集合.

在MFC中很少使用异常,主要是在访问文件或序列化数据时.您仍然应该知道如何编写异常安全代码.您会在非平凡的应用程序中看到异常.可以在 MFC中的异常处理中找到

.

预处理器是不是C ++真正组成部分,但在整个MFC中广泛使用的一个区域.不管您的MFC应用程序多么简单,都会有宏.您必须对预处理器语法以及预处理器的运行方式有很好的了解.

3.工具:

虽然可以仅使用记事本编写MFC应用程序,但是这样做肯定不是很有效.纯文本编辑器可能是学习该平台的一个好主意,但是当需要满足里程碑和最后期限时,您肯定会想要使用功能强大的IDE.

MFC几乎暗示了Visual Studio的使用,我将假定您正在使用它.如果您使用的是VS6或VS2010(或更高版本),则可以访问 MFC类向导.这是您将经常使用的工具.为了安全地操作它,您必须熟悉它为您生成的代码.试一试,检查生成的代码,然后尝试构建它的思维模型.如果仍然没有意义,则应稍后返回.

几乎可以肯定,MFC类向导将生成预处理程序代码.它隐藏了您需要了解以安全使用的大量复杂性.使用IDE浏览预处理器宏,尝试在您的脑海中扩展它们,并查看您是否了解生成的代码.如果您在解开宏调用时遇到困难,请让编译器使用/P(预处理到文件)编译器选项.

有时,您必须查看或调试MFC源代码.为了使源代码可用于源代码浏览和调试器,您必须设置 VC ++目录以包括以下内容(如果尚不存在):

$(VCInstallDir)atlmfc\src\mfc
$(VCInstallDir)atlmfc\src\mfcm
$(VCInstallDir)atlmfc\src\atl

取决于IDE,这可以通过工具->选项:项目和解决方案-> VC ++目录或项目设置的属性表来完成.

查找帮助:虽然MSDN是文档的最佳资源,但是MFC部分感觉它处于维护模式,并且没有Windows API文档那么受关注.如果发现缺少MFC文档,请查找相应的Windows API文档,例如, CWnd::OnNcDestroy WM_NCDESTROY .后者包含有关Windows接收此消息的顺序的有价值的信息.

学习MFC

Jeff Prosise是学习MFC的综合资源.对Windows进行编程使用MFC .虽然它是过时的(于1999年发布),但这些概念在今天仍然有效.它概述了MFC的概念,并深入介绍了实现细节.如果您发现自己为生成的(预处理器)代码而苦苦挣扎,则本书适合您.

作为有价值的在线资源,MSDN提供了有关MFC开发任何方面的信息.主要概念包括:

完整列表可以在概念中找到.

>

I know a bit of C++ and C and the project I am working with now is a whole lot of MFC programming. Can someone experienced tell me the prerequisites for learning MFC.

Also, What the are best sources to learn from ?

Any particular book or video series?

I know the question is too general but answers might help me(or anyone else who is digging into MFC) a lot

Thanks!

解决方案

+1 Good question!

tl;dr: Learn Win32 - in that order.

By far the most important prerequisite to MFC is a solid understanding of the Windows API (also sometimes referred to as the Win32 API). You will also need to be familiar with a few key concepts of C++ and get intimate with the tools. My proposed list of prerequisites would be:

  1. Get a solid background in Windows API development.
  2. Familiarize yourself with relevant concepts of C++.
  3. Learn the tools.

The following is a rundown of these steps, with links to additional information.

1. Windows API:

The Windows API exposes all services through a C interface. As a consequence resource management is often tedious boiler plate code. And visible in source code (sometimes an incredible bonus when reading code). MFC is - to a large extent - an automated resource management wrapper (and utility library) around the Windows API, hiding most of the resource management and type conversions. To be fluent in MFC you have to understand what it hides.

To get started with the Windows API and all you need is a quick rundown of the major components I would recommend theForger's Win32 API Tutorial (by forgey of #winprog fame). It covers Message Handling, Windowing, Controls, and the GDI, and builds a solid foundation. If you feel like investing (well spent) time into exploring the Windows API in more detail, the best resource to date is probably still Charles Petzold's Programming Windows (not the be confused with the managed Petzold). The MSDN is also a good resource to get both an overview as well as detailed documentation for specific areas like:

2. Key C++ concepts:

MFC is implemented in terms of C++. While it predates the official C++ standard you won't find too much funky business in there. Very little template code and certainly none of the new-fangled C++11 features. Intimacy with basic C++ concepts will get you a long way.

As mentioned previously, MFC is to a large extent a resource management wrapper around Windows API. Often there is a direct mapping between Windows API resources and MFC objects (like HWND : CWnd, or HDC : CDC). If you understand constructors, destructors and object lifetime you're pretty much all set in that department.

When using MFC's template-based containers (like CMap) you will be exposed to templates, naturally. Nothing too involved there, just very basic type parameterization to reuse the container code and enable type-safe element access. An introduction to MFC containers can be found here: Collections.

Exceptions are used rarely in MFC, mostly when accessing files or when serializing data. You should still know how to write exception safe code; you will see exceptions in non-trivial applications. An overview can be found at Exception Handling in MFC.

One area which is not really part of C++ but used extensively throughout the MFC is the preprocessor. Regardless of how trivial your MFC application is, there will be macros. You have to have a very good understanding of both the preprocessor syntax as well as how the preprocessor operates.

3. Tools:

While it is possible to write MFC applications with Notepad alone it is certainly not very efficient to do so. A plain text editor might be a good idea for learning the platform, but when it comes time to meet milestones and deadlines you certainly will want to use a powerful IDE.

MFC pretty much implies the use of Visual Studio and I will assume that's what you're using. If you are using VS6 or VS2010 (or later) you will have access to the MFC Class Wizard. This is a tool you will be using frequently. To safely operate it you must get familiar with the code it generates for you. Play around with it, inspect the generated code, and try to build a mental model of it. If it doesn't make sense yet you should return later.

The MFC class wizard will almost certainly generate preprocessor code. It hides a tremendous amount of complexity which you need to understand to use safely. Use the IDE to navigate through the preprocessor macros, try to expand them in your mind, and see if you understand the resulting code. If you are having difficulty unmangling the macro invocations have the compiler output the preprocessed code for you using the /P (Preprocess to a File) compiler option.

Occasionally you have to look or debug into the MFC source code. To make the source code available to source browsing and the debugger you have to set up the VC++ Directories to include the following (if not already present):

$(VCInstallDir)atlmfc\src\mfc
$(VCInstallDir)atlmfc\src\mfcm
$(VCInstallDir)atlmfc\src\atl

Depending on the IDE this is either done through Tools -> Options: Projects and Solutions -> VC++ Directories or the property sheet of your project settings.

Finding help: While the MSDN is the best resource for documentation, the MFC section feels like it is in maintenance mode and doesn't get as much attention as the Windows API documentation. If you find the MFC documentation lacking look up the respective Windows API documentation instead, for example CWnd::OnNcDestroy vs. WM_NCDESTROY. The latter contains valuable information on the order in which windows receive this message.

Learning MFC

A comprehensive resource for learning MFC is Jeff Prosise' Programming Windows with MFC. While it is dated (released in 1999) the concepts are still valid today. It provides an overview of the concepts of MFC and goes deep into the implementation details. If you find yourself struggling with the generated (preprocessor) code this book is for you.

As a valuable online resource the MSDN offers information on just about any aspect of MFC development. The major concepts include:

A full list can be found at Concepts.

这篇关于学习MFC编程的先决条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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