MFC Analysis (5) Command Update Mechanism

zhaozj2021-02-08  198

Command update mechanism

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

In the MFC frame structure, ON_UPDATE_COMMAND_UI (ID, MEMBERFXN) can be used

Macro Specifies the status setting function corresponding to the menu or toolbar button, etc.

The menu item can be set by incoming CCMDUI object pointers in MemberFXN.

Toolban use, disable, tag, etc. attributes.

All changes in MemberfxN specified in MemberFXN will be reflected in the interface to the interface.

Its implementation mechanism is as follows

Update of a tool strip button

Since the toolbar has been visible, it is necessary to update real-time, so that MEMBERFXN checks update conditions will be continuously invited.

This is achieved by cwinapp :: OnIdle (), and WM_IdleUpdateCmDui messages.

1 When the program is idle, OnIdle will be called

OnIdle () in its base class cwinthread handles the message processing function of the main window to handle the WM_IdleUpdatecmdui message,

The WM_IdleUpdatecmDui message is sent to all subordinate windows.

2 Frame window corresponding to WM_IdleUpdatecmdui messages

Void cmdiframewnd :: onidleUpdatecmdui ()

Void cframeWnd :: onIdleUpdatecmdui ()

ONUPDATEFRAMEMENU, update menu when needed

3 Each control bar, the dialog is received by the WM_IdleUpdatecmdui message

Call ccontrolbar :: OnIdleUpdatecmdui ()

Call CControlBar :: onupdatecmdui for updates

4onupdatecmdui is a virtual function of the control bar, which will have different implementations for different controls.

Take the tools:

The command processing function of the specific window will be called for each button on it.

First see if there is a handling of reflection messages

Also support yourself

The DOUPDATE is updated in general.

DOUPDATE will be processed by the oncmdmsg of the host window.

Oncmdmsg (M_NID, CN_UPDATE_COMMAND_UI, THIS, NULL);

Its ncode parameter is CN_UPDATE_COMMAND_UI, indicating that the interface update will call the member established by ON_UPDATE_COMMAND_UI, and the information of the toolbar passes

CMDUI is transmitted to the processing function.

Final Tools will call UpdatedialogControls to update other controls on it.

Update for the second menu

1 When you are idle, OnUpdateFramemenu is called to update the menu.

The process is roughly similar to the toolbar update.

2 When the menu is opened, it is also updated.

CframeWnd :: OnIndMenupopup ()

The window will call the window oncmdmsg (m_nid, cn_update_command_ui, this, null);

Update each menu item.

Three others

When the window is connected to the command, the update function of the testistic call command is prohibited.

If the command is activated, the oncmdmsg will be handed over.

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

New Post(0)