Note: VC6.0 Adding a Custom User Message Basic Process

zhaozj2021-02-16  36

In the process of learning

First, figure out two points: (1) Whoever wants to send this message (2) Whoever wants this news.

Use a simple example to explain. Object A sends a message to B (or may be a to a).

1 Send a message

First define this message in the header file of A:

#define WM_USERMESSAGE WM_USER 30

All custom messages are represented by a WM_USER message based on an arbitrary natural number. A is an object to send a message outward, so a function of sending a message is called in a method (function) of A. B: postMessage (), because it is B accept the message, so Yes, as above.

2 accept messages

Objects accept a message, there should be three parts: the prototype of the processing function of the message in the header file; the macro in which the message map is received; and the specific implementation of the processing function of the message.

2.1 Processing function prototypes with custom messages in header files

Before the DECLARE_MESSAGE_MAP () statement, a pair of AFX_MSG plus the following form of function prototype:

AFX_MSG LRESULT OnPROCNAME (WPARAM WPARAM, LPARAM LPARAM);

For Win32, WPARAM, LPARAM is the most commonly used means of passing messages.

2.2 Macro in the implementation of the message

In the CPP file, after the Begin_MESSAGE_MAP statement, the following form is added between a pair of AFX_MSG_MAP:

ON_MESSAGE (WM_USERMESSAGE, ONPROCNAME)

The above is the end of the semicolon.

2.3 Specific implementation of the message processing function is given in the implementation file.

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

New Post(0)