First, ask questions
On the vckbase, read the implementation of the self-painting menu [Author: querw]. The application of my own ongoing projects found that the effect is good, but there are many problems. There are many defects in the design of the whole class (innate, acquired), the main problems are as follows:
- When applied to multiple document interfaces (MDI), it is not possible to customize the system automatically add menus and document template menus (for example, a list of files that cannot be-> the most recent file (MRU) menu items is automatically added to the system). The reason is that there is no function within the class to process the Cmainframe::oninitpopupmenu () message, so it does not have the ability to modify the system to automatically add menu items. (Bcmenu has this function, and the work is good)
- The author mentioned that the Bcmenu without mapping Wm_drawitem and Wm_measureitem Two messages can realize the painting function, is actually wrong. Do not map these two important messages, even if you can paint, there is a problem, do not believe that look at the picture.
Template Menu Sample in the menu editor
Using Bcmenu and mapping the execution after these two messages
Using Bcmenu does not map the execution of two messages
The original author analyzes the top-level because it is incorrect to load the submenu of the main menu (the menu) into a pop-up menu (PopupMenu). The real reason is that the MFC framework automatically invokes the CMenu two virtual functions MeasureItem () and OnDrawItem (). Therefore, when Cmenuex is derived from CMenu, and after the two virtual functions are overridden.
1. The GetMenu ()->measureitem () of the MFC framework call is equivalent to calling Cmenuex::measureitem (), which enables you to measure the size of a custom menu control.