One of the basics of VS2013/MFC programming (using the MFC Wizard to generate a single document application framework) __MFC

Source: Internet
Author: User
Tags ole

on how to install the VS2013 and MSDN, there are many tutorials on the web, again not to repeat, I believe that everyone has been installed. This MFC programming entire process uses the Simplified Chinese specialized edition VS2013 to carry on the operation. This gives you a simple example of how to generate a single document application framework.

Solutions and Engineering

The concept of solution and engineering has been discussed in the introduction of VS2013, which is revisited here. Each application is treated as a project that includes header files, source files, and resource files, which are managed centrally through engineering. In VS2013, the project is under the management of the solution. A solution can manage multiple projects, and the solution can be understood as a collection of multiple projects that have a relationship or no relationship. VS2013 provides a Solution Explorer solution browser view that displays the contents of the current solution, and when you create a new project, you can choose whether to create a new solution or join the current solution.

The view that is being displayed in the left panel of the following figure is solution Explorer, which has a solution-helloworld that has a project-helloworld with the same name under this solution.


After the application wizard builds the application, VS2013 creates a directory with the name of the solution under the path of the user's settings, which holds the automatically generated files.

Using the VS2013 Application Wizard to generate a single document application framework

Here is a brief demonstration of how to generate a single document application framework, so that everyone has an intuitive understanding, there is no understanding of the place can be saved later to look back. Follow the step-by-step instructions below:

1. Point menu bar File->new->project, Pop-up New Project dialog box, we can choose the project type.

If the installation of VS2013 after the first startup has been set to VC + +, then installed templates->visual C + + items will be expanded by default, and if VC + + is not set, you can expand to installed Templates-> Other languages->visual C + + entry. Because we are building MFC programs, under Visual C + +, select MFC, and there are three options in the middle of the dialog box: MFC applications, MFC ActiveX controls, and MFC DLLs. MFC ActiveX controls are used to build MFC ActiveX control programs. MFC applications are used to build MFC applications. MFC DLLs are used to generate MFC dynamic-link library programs. Of course we want to select an MFC application.

The lower part of the dialog box has the name, location, solution, and solution name four settings. The meaning is as follows: Name--project name, location--Solution path, Solution name--Solution name. Here the name we set to "HelloWorld", the location is set to "c:\users\zhaoyinhui\documents\visual Studio 2013\projects" path, the solution name defaults to the same name, Of course can be changed to other names, here we do not make changes, also use "HelloWorld". Click OK button.


2. The MFC Application Wizard dialog box pops up with the "Welcome to MFC Application Wizard" above, showing the default settings for the current project. The first is that this project is a multiple-document application. If you immediately click the "Finish" button below, you can generate a multiple-document program with the settings listed above. But our example is to create a single document application, so click Next to continue with the setting.

3. The next pop-up dialog box has an "application type," which, of course, lets you select the application type, and we see Four types: Single document, multiple documents, based on dialog boxes, and multiple top-level documents. We select a single document type to generate a single document application framework. A single document application runtime is a single Window interface.

The resource language for this dialog box also provides a choice of language, which is chosen by default in Simplified Chinese. "Project Type" can be selected in engineering style, we choose the default Visual Studio style. MFC's use has two options: using MFC in dynamic-link libraries and using MFC in a static library way. When you choose to use MFC as a dynamic-link library, the MFC classes are accessed as dynamic-link libraries, so our application itself is smaller, but when you publish the application, you must add the necessary dynamic link libraries so that you can run the program correctly without installing VS2013. When you choose to use MFC in a static library, the MFC classes are compiled into the executable file, so the application's executable file is larger than the previous, but can be published separately, without additional libraries containing MFC classes. Here we use MFC by default in the dynamic link library mode. Click the Next button.

4. The upper part of this pop-up dialog box with document support is available to add OLE support to the application, specifying the compound document type for the OLE option. The OLE attribute is not required for this example, and the default value "None" is used. Click the Next button.

5. The new dialog box that pops up has "document template Properties" written above. File extensions can set the extension of files that the program can handle. dialog box Other options can also change the title of the program window. We all use the default settings and click Next.

6. The dialog box that pops up at this point is database support. Used to set database options. This wizard can generate the code required by your database application. It has four options:

None: Ignore all database support;

Header files only: Contains header files that define database classes, but does not generate database classes or view classes that correspond to specific tables;

Database view without file support: Creates a database class and a view class corresponding to the specified table, without attaching standard file support;

Provides a file-supported database view (T): Create a database class and a view class that corresponds to a specified table and attach standard file support.

This example selects the default value "None" and does not use database attributes. Click the Next button.

7. The dialog box that pops up is about user interface features, which are user interface features. We can set the Maximize button, minimize the button, the System menu and the initial status bar. You can also choose whether to use the menu bar and toolbars to generate simple applications or to use the ribbon. Here we all choose the default setting. Click Next to go to the next step.

8. The Advanced Features dialog box pops up at this time. The advanced features you can set include printing and print preview. The number of files on the recent file list item can set the number of recently opened files below the File menu in the program interface. We still use the default values. Click the Next button.

9. Pop-up "Generated Classes" dialog box. In the upper section of the dialog box, the Generated Classes list box lists the 4 classes that will be generated: A view class (Chelloworldview), an application Class (Chelloworldapp), A document class (Chelloworlddoc) and a main frame window class (CMainFrame). In several edit boxes below the dialog box, you can modify the default class name, the header file name of the class, and the source file name. For a view class, you can also modify its base class name, the default base class is CView, and several other base classes can be selected. Here we still use the default settings. Click the Finish button.

The application wizard finally builds the application framework for us and automatically opens the solution in Solution Explorer (see the first picture above).

Compiling a program that runs a build

Point menu of the build-> build HelloWorld compiler, and then click Debug-> Start Debugging (shortcut key CTRL+F5) run the program, you can also directly point to debug-> start debugging (shortcut key Ctrl+f5), Then VS2013 will automatically compile the link to run the HelloWorld program. The results page looks like this:


Finally saw the interface. The use of various interfaces and controls will continue to be explained in future tutorials. Welcome to the Blog Exchange, your attention is my motivation to move forward.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.