Six key technologies of MFC

Source: Internet
Author: User
Tags message queue

Video tutorial Address watch : Http://pan.baidu.com/s/1mhKQ6kK

1. Six key technologies of MFC
Sad
A) MFC program initialization process:
Derive an application class from the CWinApp class;
Use a global variable defined by a derived class (Theapp);
In the predefined header file "stdafx.h", disable "windows.h" instead of the MFC header file that begins with AFX;
The compile settings are selected with the "use of MFC in a Static Library";
In the CWinApp class, rewrite the InitInstance function as the program startup code.

b) message map:
Declare_message_map declares 2 static member variables and 1 member functions in the header file:
(emphasis is on a struct array: associating some messages and functions)

BEGIN_MESSAGE_MAP defines the initialization of 2 static member variables and the definition of a function in the source file.
End_message_map the end statement of the definition of a struct array in the source file


c) Other four key technologies: Runtime type identification (RTTI), dynamic creation, persistent saving, and message distribution.


For example, set the window icon.

2, SendMessage and PostMessage functions are message transfer functions, the format of two functions: (Interview questions)
LRESULT SendMessage (HWND hwnd,uint msg,wparam wparam,lparam LPARAM);
BOOL PostMessage (HWND hwnd,uint msg,wparam wparam,lparam LPARAM);

The differences between the two function messages, SendMessage and PostMessage, are:
A) The return value type is different: the meaning of the 4 parameters of the two function is the same, only the return value type is different
(In fact, from the data they are a 32-bit number, but the meaning is not the same),
LRESULT represents the return value of the message being processed, and BOOL indicates whether the message was successfully delivered.
b) The PostMessage is asynchronous and the SendMessage is synchronous.
PostMessage only the message into the window message queue, regardless of the result of the processing of the message is returned;
SendMessage waits for the message to be processed before returning.
c) If the message is often sent using SendMessage within the same thread, it is fast and can get the returned message processing result.
Between different threads or processes, it is common to use PostMessage to send messages into the message queue of the target window.
The target window is then distributed through the message loop for processing by itself.

3. Type of message:
A) system message: number between 0-wm_user:
b) User message: number greater than wm_user (programmer)
c) User messages are primarily used for data transfer between windows;


4. The members of the CWinApp class are introduced:
A) M_pszappname: from the CWinApp constructor is fed, if not sent to find stringtable, if not the last to find the execution file name;
b) M_hinstance: The Explorer of all resources: the resources in any resource view are actually obtained through this handle.

Six key technologies of MFC

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.