Wm_measureitem in the custom menu is sent only once.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.