Most
You need to dynamically display hidden menu items. When programming, if different menus need to be used in different scenarios, the general practice is to prepare two menu resources and repost a menu as needed to replace the previous one. This method is relatively simple, but if there are many changes, too many menu resources need to be prepared, so the consumption of resources cannot be ignored, so there will also be
CodeTo dynamically modify the menu. The insert and delete operations are used here.
Of course, the so-called display and hiding can also be achieved through insertion and deletion. However, my original idea may be easier to display and hide than to insert or delete data. Because it is a self-drawn menu, I assume that if the height of the menu item is set to 0 in wm_measureitem, the menu effect can be hidden. So I used this principle to modify the code. However, the actual effect is not as expected. After debugging, we found that the wm_measureitem message is sent only once, that is, when the menu is displayed for the second time, the size returned by the first wm_measureitem message is used. In this way, it cannot be modified dynamically.
The problem is that the self-drawn menu dynamically calculates the width required by the text to determine the width required by the menu. However, because the wm_measureitem message is sent only once, the menu width will not be changed if the menu text is modified dynamically, so that the modified menu text is truncated.
The problem is found, but there is no good solution. It seems that when you need to modify the self-painting menu, the best way is to delete it and then re-insert it.
Finally, I felt that too many mistakes are often taken for granted. Some solutions seem unreasonable and are often the most reasonable.