MFC Windows Program Design (Second Edition) Essence Concentrated Notes

zhaozj2021-02-16  46

"MFC Windows Program Design (Second Edition)" is a classic book that uses MFC (not Win32 API) to perform 32-bit Windows applications. Author Jeff Prosise, is known as Petzold in the MFC field. The author wrote in the foreword: "My goal is to write a good book that can be comparable to the eternal, no right" programming windows "written for C-programmers." This book is not unique in it does not start with the AppWizard wizard build program, but directly uses the MFC class library, using the coupling buffer procedures between various types, compared to other (especially those who are all domestic) books. Can give a new feeling. I found this book at the school library. At that time, the feeling was: Mom, the big life of life is too exciting. I didn't expect to have such a new classic in that pile of old antiques. I hope to get it with a summer vacation. After reading each chapter, I will write a book notes and some my own ideas, I hope I can help you have some netizens who are lucky. Because "You have a chance every day, you will have someone else, you may not know what he knows, but maybe he will become your friend or confidant.", I hope everyone will support it. "

Chapter 1, Hello MFC

Essence Concentration: We all know that every Windows program starts with WinMain (), and the MFC is of course no exception. But in the MFC, it is hidden. The MFC defines a global application object (aunt, it is theApp), and each global object is completed by the startup code constructor before the main program entry point (entrypoint). In other words, the program will have a THEAPP object before entering WinMain (). This way, theApp member function can be used for us. That is, WinMain () is played ... WinMain () first calls theApp member function initInstance () virtual function (to overwrite), construct the main form, and display update, then call again Run () (not covered), enter the message loop. When designing the SDK program, the message always calls a window process (WndProc ()) indicating its existence. At the same time, it is usually four parameters associated with this call: the message finger window handle, a message ID and two 32-bit parameters called WPARAM and LPARAM. The latter two parameter values ​​varies depending on the message. In the MFC, the message mapping replaces the window process as a communication interface between the message and its processing. Any class derived from CCMDTARGET can contain message mappings. Message mapping is a table that interacts a message with its handle function (as a member function as class). It is MFC to avoid a way to use a lengthy virtual table (vTable) (trim, if each class in the memory has a virtual function table, each class object instance has a pointer VPointer (4 words Section) Point to that table, this memory consumption is not estimated, it is also redundant). The MFC solves the problem with three macros. Therefore, add a message mapping to a class, do three work: 1) By adding the DECLARE_MESSAGE_MAP statement, declare message mapping; 2) By placing the macro to perform message mapping, corresponding The class will messages between the call to becom_message_map and end_message_map; 3) Adding a member function definition processing message. Regarding the situation of the message mapping work mechanism, interested netizens can refer to "In-depth shallow MFC", which is very detailed. This book also provides a method of self-bucing a Windows program. Win32 Application is selected in New-Project, and then A Empty Project is selected in the next window. After entering the main environment, add a file with Project-Add to Project. Before compiling, remember to change the compilation option to the USE MFC in A Shared DLL.

转载请注明原文地址:https://www.9cbs.com/read-26390.html

New Post(0)