Analysis of WTL-WTL Frame WTL Analysis (2)

xiaoxiao2021-03-06  63

ATL message processing macro

The purpose of the message mapping is to implement processWindowMessage (). The ProcessWindowMessage () function is a key logic of a window function.

A total of three messaging macros, respectively correspond to three types of window messages - normal window messages, command messages (WM_COMMANS), and notification messages (WM_NOTIFY).

The purpose of the message processing macro is to link messages and corresponding processing functions (member functions of the window).

· Ordinary message processing macro

There are two such macros: message_handler and message_range_handler.

The first macro will join a message and a message handler. The second macro will join a message within a certain range and a message processing function.

The message processing function is usually the following:

LResult MessageHandler (Uint UMSG, WPARAM WPARAM, LPARAM LPARAM, BOOL & BHANDLED);

Note the last parameter bhandled. Its role is whether the process is handled to handle the message. If it is False, the message MAP's other handler will process this message.

Let's take a look at the definition of Message_Handle:

#define message_handler (MSG, FUNC) /

IF (UMSG == MSG) /

{/

Bhandled = true; /

Lresult = func (UMSG, WPARAM, LPARAM, BHANDLED); /

IF (bhandled) /

Return True; /

}

In the above code, first determine if it is a message you want to process. If yes, then call the message processing function indicated by the second parameter to process the message.

Note BHANDLED, if set to True in the message processing function, then after completing the message processing, you will enter the RETURN TRUE statement to return from the ProcessWindowMessage () function.

If BHANDLED is set to false when calling a message processing function, it will not return from the ProcessWindowMessage, but continue to execute.

· Command message processing macro and notification message processing macro

Command message processing macro has five --command_handler, command_id_handler, command_code_handler, command_range_handler, and command_range_code_handler.

Notification message processing macro has five --Notify_Handler, Notify_ID_Handler, Notify_RANGE_HANDAL, NOTIFY_RANGE_HANDAL and NOTIFY_RANGE_CODE_HANDLER

We no longer analyze.

Through the above analysis, we know how ATL implements the window function logic. So how is the ATL package the window function? In order to understand the package method of the ATL, you must also understand the window Subclass and other technologies in the ATL. After analyzing these technologies, we will then analyze the encapsulation of the ATL to the window message processing function.

Expand window features

We know that the function of the Windows window is specified by its window function. We want to develop a window function when you create a Windows application. The function of the window is implemented by defining the corresponding to certain messages.

At the end of each window processing function, we generally use the following statement:

DEFAULT:

Return DefWindowProc (Hwnd, Message, WPARAM, LPARAM);

It means that for unprocessed messages, we pass it to Windows's true window function. In addition to providing this default window function, Windows provides some predefined window functions for some standard controls.

When we register the window class, we specify the window handle function of the window class.

The function of the extended window class is to change the processing logic of some messages in the window function.

Let's take a few techniques for how many extended window functions, and how the ATL is implemented.

Dead and chain_msg_map ()

Very nature, we will derive another one on the basis of a window class. Then define different messaging functions.

Here is a simple example (this example is taken from MSDN).

Class CBase: Public CWINDOWIMPL

// Simple Base Window Class: Shuts Down App When Closed

{

Begin_msg_map (CBASE)

Message_handler (WM_DESTROY, ONDESTROY)

END_MSG_MAP ()

LResult Ondestroy (Uint, WParam, Lparam, Bool &)

{

PostquitMessage (0);

Return 0;

}

}

Class CDERIVED: PUBLIC CBASE

// derived from cbease; Handles Mouse Button Events

{

Begin_MSG_MAP (CDerived)

Message_handler (WM_LButtondown, Onbuttondown)

Chain_MSG_MAP (CBASE) // CHAIN ​​TO BASE CLASS

END_MSG_MAP ()

Lresult onbuttondown (Uint, WParam, Lparam, Bool &)

{

ATLTRACE ("Button Down / N");

Return 0;

}

}

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

New Post(0)