C + + is a kind of static data type inspection , support multi-programming paradigm programming language, support process programming , data abstraction , Object-oriented programming , making icons and other generic programming design style of the various programs .
MFC (Microsoft Foundation Classes), a class library provided by Microsoft Corporation, encapsulates the Windows API in the form of C + + classes, and includes an application framework to reduce the workload of application developers VCL is similar to an application framework. It contains classes that contain a large number of Windows handles encapsulating classes and many of the built-in controls and components of Windows. In addition, some classes of MFC are MFC/ATL generic and can be included and used separately in the WIN32 application.
Because of its ease of use, beginners often mistakenly think VC + + development must be using MFC, this idea is wrong. As the application Framework,the use of MFC can only improve the development efficiency in some cases , only play an auxiliary role, and not replace the entire WIN32 program design.
From c to C + +
In the early days of computers, people had to use computers to write programs in machine language or Assembly language.
The world's first computer high-level language was born in 1954, it is FORTRAN language?
The basic language was simplified on the basis of the Fortran language in 1964?
The C language was developed in 1972 by D.m.ritchie of the American Bell Laboratory.
C + + was developed successfully on the basis of C in the early 1980s by Dr. Bjarne Stroustrup and his colleagues at T-Bell Labs, and C + + retains all the advantages of the C language, adding an object-oriented mechanism.
Object-oriented programming is aimed at the development of larger-scale programs, the purpose is to improve the efficiency of software development? Instead of opposing object-oriented and process-oriented, object-oriented and process-oriented are not contradictory, but each has its own purpose. Learn C + +, using C + + To process-oriented structured programming, but also to use C + + for object-oriented programming?
If you want to create windows in C + +, we need to use the system API or some libraries that encapsulate these APIs, such as Win32 programming , the latter such as MFC, WxWidgets.
In fact, I think the beginning of learning C + + is of course familiar with C + + syntax , medium-term is to learn STL and other libraries, system API and familiar with C + + object-oriented thinking and general design method; The latter is the life of your C + + career, Because it has no end point, in addition to continue to deepen the understanding of C + +, but also need to learn a variety of C + + libraries, because you need to use these libraries with the help of C + + to achieve more specific things, such as some GUI libraries such as MFC, QT, WxWidgets , some game engines such as Ogre, Unreal, Bigworld , and so on, some network libraries such as ASIO, raknet, ACE and so on. Most of these libraries have a feature that they are based on C + +, encapsulating the underlying API so that we do not have to use the complex API every time to achieve the functionality we want. Of course, you can also use C + + to encapsulate these APIs, to become a library author, to facilitate others.
C + + Development History
The development of C + + language can be divided into three stages:
First Stage
From the 80 's to 1995 years. This phase of C + + language is basically the object-oriented language of traditional type, and with the efficiency of close to C language, it occupies a large share in the development language used by industry;
Phase II
From 1995 to 2000, this phase has become more and more specific in C + + due to the advent of the Standard Template Library (STL) and later Boost libraries. Of course, at the same time, because of Java, C # and other languages and hardware prices of large-scale decline, C + + has been a certain impact;
Phase III
Since 2000, due to the emergence of production programming and template meta-programming represented by Loki, MPL and other libraries, C + + has seen a new peak in the history of development, the emergence of these new technologies and the integration with the original technology, so that C + + has become one of the most complex in today's mainstream programming languages.
Programming Tips
Use New and the Delete make dynamic memory allocations and releases
Use inline inline functions override macro calls
For frequently used functions, the C language recommends using a macro call instead of a function call to speed up code execution and reduce the call overhead. But macro calls have a number of drawbacks that can cause undesirable side effects. For example macros: #define ABS (a) (a) <0? (-a):(a), this macro will go wrong when using ABS (i++).
In C + +, you should use inline inline functions instead of macro calls to achieve the purpose of macro invocation and avoid the drawbacks of macro invocation.
Using inline functions only puts the inline keyword in front of the function return type.
Using function overloading
With reference (Reference) parameter passing in place of pointers
Using default parameters
All default parameters must appear to the right of the non-default parameter.
Use STL
STL (Standard Template Library), STL code is broadly divided into three categories: algorithm (algorithm), container (container) and iterator (iterator), and includes some tool classes such as auto_ptr. Almost all of the code takes the form of template classes and template functions, which provides a better opportunity for code reuse than traditional libraries that consist of functions and classes.
The function is overloaded so that we can access the elements in the vector like an array. [12]
Using templates
Multi-generic design
C + + is now comprised of the following four "sub-languages", according to the description of effective C + +, the third edition of the first section:
1,C sub-language . C + + supports almost all of the functions of c89, mainly the part of the C language, with only a very subtle grammatical difference (such as the left and right value of the parentheses expression, refer to the C + + standard literature).
2. Object-oriented C + + language . The C + + language does not originally have object-oriented design capabilities, but as the concept of object-oriented programming and the development of languages such as Java have matured, the C + + language has developed a version that supports object-oriented functionality.
3, generic programming language . The powerful (but easily runaway) template feature of C + + enables it to do a lot of work during the compilation period, thus greatly improving the efficiency of the run-time.
4.STL (Standard Template Library of C + +). With the development of STL, it has gradually become an indispensable part of C + + programming, its efficiency may be lower than the general native code, but its security and standardization make it popular.
In addition, the new features that are included in the TR1 such as c++0x will be implemented in development and testing.
MFC features
programming language functions are essentially all derived from APIs, so applications developed with them can work in Windows Messaging mechanisms and drawings, adhering to Windows as an internal implementation of an operating system.
Finally to understand that MFC is not just a functional interface development system, it provides the majority of the class used for interface development, associated with a window of the action, but it provides a class is not associated with a window, that is, the role of the class is not an interface class, do not implement a Window object control (such as Create, destroy), It is a class that implements internal processing in Windows (most of the programs written in MFC are run in Windows), such as the management class for a database. The most time spent in learning is messaging and device environments , for C + + and MFC.
MFC Programming Benefits
The C + + language is very widely used. In particular, in the lower-level programming and system-wide programming is the traditional advantage of C + + application. In the database and multimedia , C + + with its excellent stability and won the honor.
In the face of the underlying program , it can be easily combined with the Windows API or driver, is to use the API functions directly in their own code, and the API and driver materials are based on the C language, which makes VC programmers easier to use the Windows API. This creates a very interesting phenomenon, that is, VC programmers to pay more efforts to learn, but once mastered, the development of other areas of the program or use of third-party software, such as industrial control programs, because the underlying program is written in C language, Instead, VC programmers can quickly master the field of programming technology. And many other programming languages can't even find the relevant information. This means that VC (MFC) is actually a difficult way to get started, but it's a very easy language framework to expand learning. VC has no advantage if it is confined to a certain area, but if you develop a new domain application or the program involves multiple application areas, you can reduce the frequency and difficulty of repetition, and the advantages of VC (MFC) will be immediately apparent.
MFC related
MFC uses "AFX" as a prefix for all global functions and global variables. Because in the early development phase of MFC It was called "Application Framework Extensions" abbreviated as "AFX". AFX provides a high level of abstraction of the Windows API, creating a new object-oriented AFX API, but it's too complex for newbies, so the AFX team has to start over. Later they created a set of C + + classes, which is MFC. The name MFC was used too late to modify the references.
MFC is not included in the Free Express version of Visual Studio 2005/2008.
MFC, as a powerful competitor, designed Owl (Object Windows Library) for the Borland Turbo C + + compiler to be released at the same time. But in the end, Borland stopped the development of owl and soon purchased the MFC header files from Microsoft, the dynamic link library, and so on, Microsoft did not provide complete MFC integration support. Borland then released the VCL (Visual Component Library) to replace the owl framework.
MFC Extended DLL
Each DLL has some type of interface: variables, pointers, functions, classes accessed by the client program. Their role is to allow the client program to use the DLL,MFC extension DLL to have a C + + interface. The exported function can use the C++/MFC data type to make parameters or return values, and when exporting a class, the client can create a class object or derive the class. Also, DLLs and MFC can be used in DLLs.
The MFC class library used by Visual C + + is also a DLL that is guaranteed to exist in a DLL, and the MFC extension DLL dynamically connects to the MFC code library, and the client program must also dynamically connect to the MFC code Library's DLLs. (Here are two DLLs, one is our own DLL, a DLL loaded MFC class Library) Now the MFC code Library DLL has more than one version, the client program and extension DLLs must use the same version of the MFC code DLL. Therefore, in order for MFC extension DLLs to work well, both extension DLLs and client programs must dynamically connect to the MFC code library DLLs. This DLL must be on the computer where the client program is running.
MFC Version Update
Visual C + + 6.0 MFC 6.0 (Mfc42.dll)
Visual C + + MFC 10.0 (Mfc100.dll)
C + + Programming Development
Development method
- Compiler: Gcc,clang, etc.
- Editor: generally Vim/emacs
- Make:gnu make or BSD pmake, etc., function and usage are basically the same
- Version management: Cvs,svn,git, etc.
- Code read: CSCOPE,CTAGS,LXR, etc.
Integrated development Environment (IDE)
- Visual Studio (Visual C + +)
- Borland C + + Builder
- Eclipse (Myln + CDT + MinGW32 + GCC)
- Dev-c++ (MinGW32 + GCC)
- Code::Blocks (can be used with multiple compiled kernels)
- CodeLite
- C-free
- QT Creator, etc. based on the QT development Framework IDE
Common C + + development tools
1 . Visual Studio
Visual Studio is a Microsoft-launched development environment that is currently the most popular Windows platform application development environment. In Visual Studio, you can create applications and network applications, as well as smart device applications and office plugins. Starting with 7.0, Visual Studio joined. NET technology, a Java-like JVM. If you do not want to use. NET technology, version 6.0 is also a good choice.
Description: Visual Studio has extended the standard C + +, which is used to refer to C + + as Visual C + +, VC, which is implemented in Visual Studio. VC is currently the most widely used C + + development language, and Visual Studio is the most widely used development tool.
2 . C + + Builder
Borland company launched in 1998, is also a development tool under Windows. C + + Builder has a highly secure, reliable, and fast compiler optimization method, so the compiled software executes very fast. All original code that complies with the ANSI/ISO standard can be compiled in C + + Builder and supports the latest ANSI C++/C language features.
3 . Dev-c++
Dev-c++ is an open-source C + + programming environment under the Windows platform. It integrates many free software, such as GCC, MinGW32, and so on, with an interface similar to Visual Studio, but much smaller in size. Its disadvantage is that it is difficult to do large-scale software projects, but for beginners is a good choice.
4 . Anjuta
The Anjuta is an integrated environment for C + + programming in a GNOME desktop environment and open source software. It not only has the function of project management, interactive debugging and powerful code editing and syntax enhancement, but also can develop the program of Glade GUI directly. However, it is mainly used on Linux and UNIX platforms and does not support the Windows platform. Currently, the latest version is 2.4.x and can be obtained from the Anjuta.sourceforge.net site.
5 . Code::Blocks
Code::Blocks is an all-in-one, cross-platform, integrated development environment for C/+ +, which belongs to open source software. It offers a wide range of engineering templates, including console applications, dynamic connection libraries, OpenGL applications, QT applications, Win32 GUI applications, and more. Another attraction of Code::Blocks is that it has a wide variety of plugins, including code formatting, class wizards, code completion, code statistics, to-do lists, and windowsxp skins. In addition, it supports not only the GNU GCC compiler, but also various compilers such as Ms Visual C + +, Borland C + + compiler 5.5, and digital Mars C.
6 . Eclipse
Eclipse is the most well-known integrated development environment in the current open source platform. Originally used primarily to support Java language programming, currently through the plug-in CDT can also be used to develop C/D programs. Because it is only a framework, so many plugins are a big feature of it. This makes it difficult for eclipse to have the flexibility of other IDE environments that support a single language.
In addition, there are many Ides that support C + + development, such as visual Slick Edit, NetBeans, understand C, and so on, so that readers can choose their own development environment for their own needs.
Visual C + + 6.0 Introduction to the development environment
The Visual C + + IDE typically consists of 3 parts: Developer Studio, MFC, Platform SDK. with Visual C + + writing code does not necessarily mean using MFC , using the STL , ATL , writing the SDK there is no limit to the program. The Platform SDK is based on the Microsoft C + + compiler as the core, with MASM, supplemented by a number of other tools and documentation.
Table 1-1 File types
File type |
Description |
File type |
Description |
Active Server Page |
ASP file |
Binary File |
binary files |
Bitmap File |
Bitmap file |
C + + Source File |
C + + source program Files |
C + + Header File |
C + + header file |
Cursor File |
Cursor file |
HTML Page |
HTML file |
Icon File |
Icon file |
Macro File |
Macro file |
Resource Script |
Resource Script File |
Resource Template |
Resource templates |
SQL Script File |
SQL language script file |
Text File |
Text file |
|
|
Due to its powerful features, Visual C + + 6.0 has a very large number of predefined project types, as shown in table 1-2.
Table 1-2 Project Types
Project type |
Description |
Project type |
Description |
ATL COM AppWizard |
ATL programs |
Database Project |
Database |
Win32 Dynamic-link Library |
Win32 Dynamic Link Library |
DevStudio add-in Wizard |
Automatically embed execute file macros |
Custom AppWizard |
The Custom Program Wizard |
ISAPI Extension Wizard |
Internet Server or Filter |
Makefile |
Make file |
MFC ActiveX Control Wizard |
Active x Control |
MFC AppWizard (DLL) |
MFC dynamic Link Library |
MFC AppWizard (EXE) |
MFC executable File |
WIN32 Application |
Win32 Program |
Win32 Console Application |
Win32 Console Program |
Win32 Static Library |
Win32 Static Library |
Utility Project |
The project is used as a container for other sub-projects, thus reducing the time of the sub-project's linking |
Classics
"The C + + standard library:a Tutorial and Reference" (c + + standards Library: Self-study tutorials and reference manuals)
Standard C + + iostreams and locales:advanced Programmer ' s Guide and Reference ("Standards C + + input and output streams and localization")
"Effective STL"
"Generic programming and the stl:using and extending the C + + standard Template Library" (Generics programming and STL)
"C + + Network Programming" ("C + + Networking Programming")
"Thinking in C + +" ("C + + programming Idea")
"Ruminations on C + +: A decade of programming Insight and Experience" ("Meditation on C + +")
Inside the C + + object Model ("Deep Exploration of C + + objects Models")
Design patterns:elements of reusable object-oriented software (designing mode: The basis of reusable object-oriented software)
"Large-scale C + + software Design" (large-scale C + + programming)
"STL Source Code Analysis"
"The C + + standard:incorporating Technical Corrigendum No. 1"
"C + + Primer Chinese Version (4th edition)"
"C + + Primer Plus (fifth edition)"
Appendix:
With the determination of the C++98 standard, Iostream.h has been canceled, at least in VC2010 below is the case, instead we have to use <iostream> header file instead, Iostream.h is a C + + header file, not C, As a result, the standard was changed to <iostream>. and C's header file stdio.h and so on can still continue to use, this is to be compatible with C code. But they still have a corresponding C + + version, such as <cstdio> <cstdlib>. Remember, VC2010 uses C + +-style header files instead of C-style header files, unless you are in use.
VC starting with version 2005, Microsoft introduced a series of security-enhanced functions to enhance the CRT (C runtime), which corresponds to strcpy_s. _s means safe, the same reason, Strcat is the same. So to solve this problem, we can replace strcpy with strcpy_s, but note that strcpy_s is not available to all compilers, so if you want to cross the compiler, define _crt_secure_no_ as prompted in the error message. Warnings macro to deceiving it. Also note that not all of the reinforcing functions are _s behind the buttocks, such as STRICMP, the enhanced version of the string comparison function, is the name _stricmp.
C + + & MFC