MFC Analysis (3) Processing Process of Command in Document View Structure

zhaozj2021-02-08  260

Processing process of commands in the document view structure

FMD (http://www.fmdstudio.net)

(As an example of MDI document view)

On the interface of the application, the elements such as menus, toolbars are included, and after electing these elements, a command will be sent to the program. At the same time, there are other forms such as shortcuts, such as shortcuts, and more.

In the document view structure, the program includes a primary frame window, and the specific open file includes several related objects such as the data object (cDocument), and the Window container (CFrameWnd). After the command is sent, it will be subjected to the specified object in accordance with certain flows, and the member function in the object is resolved.

Command to send

Press a certain item on the menu or toolbar, (or press the corresponding hotkey) Send a WM_COMMAND message to the window.

The WM_COMMAND parameter includes 3 parts:

WNOTIFYCODE = HiWord (WPARAM); // Source Type

WID = loword (wparam); // Command ID

HWndCTL = (hwnd) lparam; // Source window

The most important thing is WID, it is the specific command. The value is the ID _ ????? that is a menu item, a tool button, or a button combination.

In the CWND object, WM_COMMAND is processed by the oncmdmsg () response.

In the MFC program framework, oncmdmsg () currently sends a command to a specific object processing in a specific process.

Two ordered ID

Typically, the value range of the command ID is: 0x8000 -> 0xDFFFF

// 8000 -> DFFF: User Commands

// E000 -> EFF: AFX Commands and other Things

// f000 -> ffff: Standard Windows Commands and Other Things ETC

// e000-> e7ff standard Commands

// e800 -> E8FF Control Bars (First 32 Are Special)

// E900 -> Eeff Standard Window Controls / Components

// EF00 -> EFFF SC_ MENU HELP

// f000-> ffff standard strings

Three ordered flow

At the beginning of the command, it is passed to the current window as a parameter of the WM_COMMAND message.

If no file is opened, WM_COMMAND is sent to the parent window (CMDIFrameWnd)

If there is a file, WM_COMMAND sends to the activated sub-frame window cmdichildwnd)

In addition, CView, cDocument is derived from ccmdtarget, which can respond to commands, but they do not respond to a general window message.

Oncmdmsg () in cmdiframewnd and cmdichildwnd will forward to CWINAPP, CView, or CDocument as needed.

Oncmdmsg in these class ccmdtargets will look for message mapping items in this class to find the handler.

(1) If there is no file to open, only the main frame

Summary: In the main frame inspection command processing, if not found, the application class is handled.

Command flow: Main Frame -> Application Class.

specific process:

1 call cmdiframeWnd :: oncmdmsg

{

IF (with sub-frame)

{

Hand to sub-frame processing; cmdichildwnd :: oncmdmsg

Return;

}

CframeWnd :: ONCMDMSG

Return;

}

2cframeWnd :: oncmdmsg is:

{

....

The function will return if there is a process function of the command in the framework.

IF (cwnd :: oncmdmsg)

Return;

// If there is no processing in the frame, give it to the application class processing command.

CWINApp :: oncmdmsg

}

3 If the command is not processed in the frame, turn to CWINAPP processing.

CWINApp :: oncmdmsg

(2) There is an open document, there is a sub-frame, view object, document object

Command flow direction: Subframe reception -> View object processing -> Document Object Processing -> Document Template Processing

-> Subframe processing -> Application object processing

If it is handled at a certain level, the process jumps out.

specific process:

WM_COMMAND is sent to the subframe, including the following steps in cmdichildwnd :: oncmdmsg:

1 Treatment of view objects to activate on subframes first

Execute cview :: oncmdmsg

Call the oncmdmsg of the base class, find and execute the command processing,

If you are not found, hand it to the document object to handle the command.

2 execute cDocument :: oncmdmsg

Find command processing functions in the document object.

If not found, the document template is handled.

3 Execute CDOCTemplate :: ONCMDMSG

If the command is not processed, return to the sub-frame, sub-frame processing

4 Subframe Base Category :: oncmdmsg

If the command is not processed, the application object is handled

5 execute cwinapp :: oncmdmsg

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

New Post(0)