Learn the summary of "in-depth introduction to MFC" (II)

Source: Internet
Author: User
Tags ole

Chapter 1 Overview Application Framework

 

1. Application Framework: we dig out a part of a complete set of modules (such as MFC and OWL) written by others, and give an application object to instantiate them one by one, some of these parts are allowed to be modified to make the program more suitable for personal needs. An extended collection of classes that cooperate to support a complete application architecture or application model, providing more complete application development support than a simple set of class libraries.

 

2. Class Library: A group of classes with object-oriented nature, which makes some functions of the application easier to implement, these functions include numerical operations and data structures, drawing, and memory management. These classes can be integrated into the application in a single piece.

 

3. Several Related Concepts: Ole controls, OCX controls, and ActiveX Controls

 

4. Browse MFC. The MFC class can be divided into several major groups:

General purpose classes: Provides string class, data processing class, exception handling class, and file class... And so on

Windows API classes: Used to encapsulate windows APIs, such as window, dialog box, and DC... And so on

Application Framework classes: this group of classes, including document/view, message pump, message ing, message transmission, dynamic creation, file read/write, etc.

High level organization actions: including the toolbar, status bar, split window, and scroll window

Operation System extensions: including Ole, ODBC, Dao, mapi, WinSock, and ISAPI

 

5. cobject is the first of ten categories. Any class derived from cobject can inherit several important object-oriented properties, including rtti (runtime type recognition) and persistence (Object Storage), dynamic creation (dynamic creation), diagnostic (error diagnosis)

 

6. Common afx global functions: afxwininit, afxbeginthread, afxendthread, afxformatstring1, afxformatstring2, afxmessagebox, callback, afxgetapp, afxgetmainwnd, afxgetinstance, afxregisterclass

 

7. serialization refers to writing or reading object content from a file. In this way, the object's life can continue after the program ends, and then be read after the program is re-activated. Such an object can be called "persistent" (permanent)

 

8. position is a unique data type of MFC, indicating the element position in the collection object. It is often used in MFC collection classes.

 

 

Chapter 2 life and death of the MFC Program

 

1. The libraries required by the MFC program include: C Runtime function library (libc. lib or msvcrt. lib), Windows API function library (gdi32.lib, user32.lib, and kernel32.lib), and MFC function library (afx function library, mfc42.lib)

 

2. header file required by the MFC program: stdafx. h, usually including afxwin. h file. The file contains all the statements of the MFC class and the declaration of the Windows API function. h

 

3. Content of the three resource files: afxres. h contains the standard resource ID, such as id_file_new; resource. h contains the User-Defined resource ID ;*. RC Resource Description file, which is a text description of all resources.

 

4. afx_msg is equivalent to a space character and has no practical significance.

 

5. The callback function can be a global function or a static member function (without the this pointer)

 

6. cwinapp replaces winmain's position in the SDK (that is, most of winmain's important tasks are completed by cwinapp's member functions), while cframewnd replaces wndproc's position in the SDK

 

7. In addition to the general style, you can also set the extended style. To make the extended style take effect, the window must be created using the: createmediawex function instead of the: createwindow function.

 

8. The precreatewindow function registers the window class, modifies the lpszclass of CS, and provides the opportunity to modify other attributes of CS. Next, it will call: createwindow or: createwindow Wex to create a window.

 

9. The onidle (long lcount) function is used to process idle time and can be reloaded.

 

 

Chapter 2 simple and complete: MFC backbone Program

 

1. Document is the data body, and view is the data surface. We use cdocument to manage data and collections classes (a set of collection classes specifically used to process data in MFC) to process actual data. We use cview to display data, use CDC and cgdiobject to draw a graph.

 

2. You can view the document through the view and change the document through the view. View is an interface for external display of document, but it cannot be completely independent. It must exist in a so-called document frame window.

 

3. You must use the document frame window to edit a document, and then send the message to cview.

 

4. the same resource ID can correspond to multiple types of resources. For example, a resource ID can correspond to a menu, an icon, and a string. This resource ID is often used to generate these resources at a time when the Framework Window is created.

 

5. Supports the drag and drop mouse drag-and-drop functions and double-click the function to open three functions: cwnd: dragacceptfile, cwinapp: enableshellopen, and cwinapp: registershellfiletype.

 

Note: This chapter introduces the startup of the MFC program. I have written an article about the startup process before reading this book, which is more detailed than the process in the book. Please wait and sort it out.

 

 

Chapter 2 document-View

 

1. In MFC, four classes are used to manage and express the document/view structure. The four classes are cdoctemplate, cdocument, cview, and cframewnd. The relationships between them are clearly shown in the following figure:

I also summarized the definitions of these four classes and sorted them out when I had time.

 

2. Many collection classes are designed in MFC to process data sets in batches. STL is used for processing in C ++. I don't know how MFC supports STL. It seems that some support is not very good.

 

3. This chapter on serialize takes a lot of space and has a question: the carchive class has actually been defined by operator by default <and operator>, operator> is reloaded in implement_serial. There are some differences with the default one, but why only heavy-load operator >>, not heavy-load operator <? It is not stated in the book. The reason should be that the default operator <can be used to complete the task.

 

4. When using serialize, The carchive: writeobject and carchive: readobject functions must be called at last. Both functions must read or write class information in a certain format, does this limit the document format? It is useless to process some generic documents. I think this is very bad. I am not ready to use this function in the future.

 

 

Chapter 2 message ing and Command Transmission

 

1. Message ing and command passing are two different concepts. Message ing is the basis for all message flows, while command passing is based on message ing. For wm_command messages, different transmission methods and routes are designed for wm_xxx messages.

 

2. MFC divides messages into three categories:

2.1 Command Message (wm_command): a user's command program performs some operations, which may come from menus, acceleration keys, or toolbar buttons. The MFC program mainly relies on the menu item identifier (menu ID) to identify. Anyone derived from the csf-target class is eligible to receive command messages;

2.2 standard Windows message: wm_xxx except wm_command is regarded as this type. Any message derived from the cwnd class can receive this message;

2.3 Control notification message: a message is generated by a control to notify its parent window (usually a dialog box. This type of message is also presented in the form of wm_command, and the new control appears in the form of wm_notify.

 

3. The strange transmission route of command messages has been summarized in chapter 3rd.

 

 

Chapter 2 MFC and dialog box

 

There seems to be nothing to talk about in this chapter.

 

Chapter 2 enhancement of view functions and improvement of repainting Efficiency

 

1. Here, the enhancement of the view function refers to how to update other views when multiple views point to one document at the same time. It is implemented through a function, that is, cdocument: updateallviews, which can update all views corresponding to the document.

 

2. Here, the so-called re-painting Efficiency Improvement refers to how to draw only the part of the window to be re-painted when re-drawing the view, this improves the repainting efficiency. The function cview: onupdate is called before the function cview: ondraw is called. You can analyze which part needs to be re-painted here, call the invalidaterect function to send the region parameters to be repainted. The Calling sequence of several functions is as follows: cdocument: updateallviews-> cview: onupdate-> cview: onpaint-> cview: ondraw.

 

3. The other part of this chapter also introduces the concepts and mutual transformations of logical coordinates and device coordinates. From the very beginning, I was confused about these things when I learned MFC, I still don't understand it yet. It seems that I need to find a special article. Otherwise, the drawing will definitely be a problem.

 

 

Chapter 2 Printing and preview

 

1. This chapter looks at Vertigo. How is the printing function so complicated? The complexity lies in three points: first, the process is indeed complicated. It is to use MFC to print the modifiable virtual functions and their approximate functions. We can see that the process is complex. Second, we design them to the CDC class, I don't know enough about this class. Third, how can I make it so complicated when it involves Coordinate Transformation and ing methods? Are other GUI toolkits designed so complicated?

 

2. DC is the device context. You must obtain a DC before drawing in windows. It may represent a full screen, a window, a memory, or a printer ..., DC has many elements required for drawing, including coordinate system (ing mode), origin, drawing tool (pen, brush, color ...) And so on. It is also connected to the underlying output device driver. Because of DC, the screen painting and printer painting operations in the program can be exactly the same.

 

3. Relationship between onpaint and onprint:

 

 

Chapter 2 Multi-file and multi-view

 

1. This chapter describes how to generate multiple windows for a document (that is, a document object) and how to generate multiple documents and windows. It looks complicated. In fact, as long as you know how the MFC program creates document objects, Framework Window objects, and window interface objects, these functions are easy to implement. It also takes more time to take a look at the life and death of the previous MFC, or to see the Startup Process of the MFC program I wrote.

 

2. Note that if there is a different class among document class, framework window class, and window class, they should be wrapped into different doctemplate classes. But it does not mean that the three classes in different doctemplates are different.

 

 

Chapter 2 MFC multi-thread Program Design

 

1. First, clarify the concepts and differences between modules, processes, and threads.

A module is an executable program (including EXE and DLL). Its program code, data, and resources are loaded into the memory and managed by a data structure built by the system, the data structure is called Module Database (MDB ). This book contains the information table of this structure, which includes the address datadirectory of data segments such as programs, data, and resources;

 

A process is a collection of many owners. Processes have address space (determined by memory context), dynamically configured memory, files, threads, and a series of modules. The operating system also uses a data structure to manage it, that is, process database (PDB). This structure has a modreflist that contains the list of all modules to be used by the process. It also contains a treadlist pointing to the wired process in the process;

 

The thread mainly expresses the "execution fact" of program code in the module. The system also records all related data of the thread based on a specific data structure thread database and TDB, this includes Thread Local Storage (TLS), message queue, handle table, and memory context. In TDB, A pcurrentpriority indicates the priority of the thread, a messagequeue indicates the message queue of the thread, a threadcontext indicates the address space of the thread, and a tlsarray indicates the TLS of the thread.

 

2. Thread context is the "backend" of a thread, which refers to a set of Cache Server values (including command IP addresses ). Because the thread is usually paused, you must record all the statuses of the previous moment for future recovery.

 

3. From the perspective of MFC, threads are divided into worker threads irrelevant to the user interface and UI threads related to the User Interface (UI. For the use of threads, it is better to concentrate all UI operations in the main thread, and other "purebred computing work" will be considered for worker threads.

 

4. If your program is busy with many things, but you need to pay attention to some external events at any time (possibly from hardware or from users), it is suitable to use multithreading for help.

 

5. process of generating a worker thread: First prepare a thread function for the thread, and then call the afxbeginthread function to create a cwinthread. Specify the thread function as follows:

Cwinthread * pthread = afxbeginthread (threadfunc, & PARAM );

Uint threadfunc (lpvoid pparam)

{

} // Actually, this thread function is used to represent a thread. The return function ends the thread.

Note: A New cwinthread object is added to afxbeginthread, so be sure to delete it.

 

6. The process of generating a UI thread: Because the UI thread requires a message loop, the UI thread must first derive a class from cwinthread, which can inherit the message loop of cwinthread, then call afxbeginthread to create the object of the derived class, as shown below:

Cwinthread * pthread = afxbeginthread (runtime_class (cmythread ));

Note: When the UI thread ends, make sure it generates a wm_quit message to end the thread, or call afxendthread. Do not forget to delete this object.

 

 

 

Chapter 4 Create an Appwizard

Omitted

 

 

Chapter 4 "stand on the shoulders of people"-use components & ActiveX Controls

 

1. Three types of controls: vbx (Visual Basic extension) in VB, VCL (visual component library) in Delphi and C ++ Builder) and Visual C ++ ocx (OLE Control extention), also known as ActiveX Control

 

2. There are two components in the component Gallery of VC: Components and ActiveX controls. The difference between the two is that components is some written C ++ classes. Gallery basically only encapsulates these C ++ classes and puts them together with other resources into a package, when these components are added, the entire program code is obtained. The ActiveX controls component is in the. ocx file. When added, it only contains code on how to use the control. The code of the control itself is not added to the project.

 

3. The basic concepts of ActiveX controls include properties, methods, and events (so-called PME ). Property is equivalent to a member variable or data member of the C ++ class; methods is equivalent to a member function of the C ++ class; event is equivalent to a notification (notification message) in a Windows control, such as bn_clicked.

 

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.