I really started to learn VC ++, and it still felt a little hard. I forgot almost all of my previous knowledge and had to start over. But fortunately, there are still some basic syntaxes, so you don't have to make a lot of effort. There are still some object-oriented knowledge, so you don't have to re-learn. You just need to know about it. Pointer knowledge is not much different. You can learn it by using it. Today, I started to enter the VC ++ hall again, hoping to open the door to my c ++ learning. This August goal: to be familiar with the single-document, multi-document, and dialog box applications of MFCProgramTo learn how to use the control in MFC. Start ~~ Keep moving ......
Step 1: Create an MFC single-document application
It's easy to open VC 6.0 (I am still using 6.0 ~~), "File"-> "new"-> "project"-> "MFC Appwizard (exe)", enter the project name, and select "Single Document" in the next step ", next, next ...... Complete.
The name of the project I created is writer. It is described here and will appear in the analysis below.
Step 2: Main Program Analysis 1. Application cwriterapp
The cwriterapp class inherits from cwinapp and manages the entire application. Each MFC windows application corresponds to a cwinapp derived class object, which can be found in writer. cpp.
Initinstance, an important initialization function of the application cwriterapp, is used to initialize the application. In this method, there is suchCodeUsed to register the document window, SDI architecture main form, and View window of a single document:
Csingledoctemplate * pdoctemplate;
Pdoctemplate = new csingledoctemplate (
Idr_mainframe,
Runtime_class (cwriterdoc ),
Runtime_class (cmainframe), // main SDI frame window
Runtime_class (cwriterview ));
Adddoctemplate (pdoctemplate );
This Code specifies the document class, Architecture class, and view class, and constructs an application with a single document view structure.
2. Document-type cwriterdoc
The document class is used to access data. The seriallize method can access data.
3. View class cwriterview
The View class is responsible for displaying program data and user operations. It can be understood as a program and user interface (UI). The design of this interface directly affects the user experience. PS. Looks like the concept of UI.
In this class, the most common function is ondraw, which is used to repaint the content displayed in the Document. When the window is generated, changed, and dragged for the first time, the program will call this method to redraw the interface. Another common function is getw.net. This function is used to obtain the pointer of a document to facilitate access to data in the document. The ondraw Function Code is as follows:
Void cwriterview: ondraw (CDC * PDC)
{
Cwriterdoc * pdoc = getdocument ();
Assert_valid (pdoc );
// Todo: Add draw code for native data here
}
In this function, call the getdocument function to obtain a document pointer and access the data in the document through pdoc.
4. cmainframe
The framework window class manages the menus, toolbar, and status bar in the window. Generally, you can create a toolbar, Status Bar, and so on in the oncreat function ...... The code is no longer pasted.
PS. add an event: "View"-> "create Class Wizard". In the displayed window, select a project, select a class name, and select the message to be added in messages, click "add function" to complete adding, and then click "edit code" to edit the code. Message maps is added here. In Windows programming, it is called an event.
Author: Hanjiang fishing
Source: grass house & land reclamation-Technical blog of Hanjiang fishing
The copyright of this article belongs to the author. You are welcome to repost this article, but you must keep this statement without the consent of the author.ArticleThe original text connection is clearly displayed on the page. Otherwise, the legal liability is retained.