Windows Programming [13]-menus and menu Resources (2)

Source: Internet
Author: User
Tags control characters
We can modify the resource file in the previous example to the following:
 
Mymenu1 menuexbegin popup "& file", 65535 begin menuitem "& New", 101 menuitem "& Open", 102 menuitem "& Save", 103 menuitem separator menuitem "E & xit ", 104 end popup "& edit", 65535 begin menuitem "Cu & T", 201 menuitem "& copy", 202 menuitem "& Paste", 203 end popup "& help ", 65535 begin menuitem "& about", 301 endend

  

Explanations:

1. In the past, menus were used to identify menu resources. menuex provides more functions.

2. Like Delphi, they use begin and end to divide statement blocks, or they can use the C/C ++ language :{...}; its annotations are also in C format.

3. In mymenu1 menuex, mymenu1 is the identifier of the custom menu.

4. mymenu1 menuex can be followed by control characters for loading and releasing: preload, moveable pure and discardable, it may be because the resource is not used ).

5. Popup indicates that this is a pop-up menu item, that is, it has a sub-menu, and you are used to using 65535 as the identifier.

6. menuitem indicates a menu item, and menuitem separator indicates a menu separator.

7. The first parameter of menuitem is the text to be displayed.

8. The second parameter (separated by a comma) of menuitem is the identifier of the menu item and an integer (1-65535). When you click the menu, the wm_command message is sent. The wparam parameter of the message is the identifier, so that we can know which menu item is clicked. This identifier is a bit like a handle, this identifier is also required when you operate this menu item.

Now we need to solve a problem: the menuitem identifiers 101, 102, 103 and so on are hard to remember. It would be nice to define them as constants with literal meanings.
In Delphi, const is used to define constants, but the resource file is system-level. You need to use the C/C ++ method to define constants. The following can be modified:

# Define idm_new 101 # define idm_open 102 # define idm_save 103 # define idm_exit 104 # define idm_cut 201 # define idm_copy 202 # define idm_paste 203 # define idm_about too many popup "& file ", 65535 begin menuitem "& New", idm_new menuitem "& Open", idm_open menuitem "& Save", idm_save menuitem separator menuitem "E & xit", idm_exit end popup "& edit ", 65535 begin menuitem "Cu & T", idm_cut menuitem "& copy", idm_copy menuitem "& Paste", idm_paste end popup "& help", 65535 begin menuitem "& about ", idm_about endend

  

Further research: There are many parameters behind each menu item to specify different functions and display effects.
For example, mft_string (a string), mfs_checked (select), mfs_grayed (disabled), mft_rightjustify (displayed on the right), and so on. The example is as follows:

# Define idm_new 101 # define idm_open 102 # define idm_save 103 # define idm_exit 104 # define idm_cut 201 # define idm_copy 202 # define idm_paste 203 # define idm_about too many popup "& file ", 65535 begin menuitem "& New", idm_new, mft_string, mfs_checked menuitem "& Open", idm_open, mft_string, mfs_grayed menuitem "& Save", idm_save menuitem separator menuitem "E & xit ", idm_exit end popup "& edit", 65535 begin menuitem "Cu & T", idm_cut menuitem "& copy", idm_copy menuitem "& Paste", idm_paste end popup "& help ", 65535, mft_rightjustify begin menuitem "& about", idm_about endend

  

After the call:


For example, mft_menubreak and mft_menubarbreak are shown in the following example:
# Define idm_new 101 # define idm_open 102 # define idm_save 103 # define idm_exit 104 # define idm_cut 201 # define idm_copy 202 # define idm_paste 203 # define idm_about too many popup "& file ", 65535 begin menuitem "& New", idm_new menuitem "& Open", idm_open, mft_menubreak menuitem "& Save", idm_save menuitem separator menuitem "E & xit ", idm_exit end popup "& edit", 65535 begin menuitem "Cu & T", idm_cut menuitem "& copy", idm_copy, mft_menubarbreak menuitem "& Paste ", idm_paste end popup "& help", 65535, mft_rightjustify begin menuitem "& about", idm_about endend

  

After the call:


Another example is mft_rightorder (right-aligned:

# Define idm_new 101 # define idm_open 102 # define idm_save 103 # define idm_exit 104 # define idm_cut 201 # define idm_copy 202 # define idm_paste 203 # define idm_about too many popup "& file ", 65535 begin menuitem "& New", idm_new, mft_rightorder, mfs_checked menuitem "& Open", idm_open menuitem "& Save", idm_save menuitem separator menuitem "E & xit ", idm_exit end popup "& edit", 65535 begin menuitem "Cu & T", idm_cut menuitem "& copy", idm_copy menuitem "& Paste", idm_paste end popup "& help ", 65535 begin menuitem "& about", idm_about endend

  

After the call:


Or mft_rightorder (right-aligned) Example:

 # define idm_new 101 # define idm_open 102 # define idm_save 103 # define idm_exit 104 # define idm_cut 201 # define idm_copy 202 # define idm_paste 203 # define idm_about timeout menuexbegin popup "& file ", 65535, mft_rightorder begin menuitem "& New", idm_new menuitem "& Open", idm_open menuitem "& Save", idm_save menuitem separator menuitem "E & xit ", idm_exit end popup "& edit", 65535 begin menuitem "Cu & T", idm_cut menuitem "& copy", idm_copy menuitem "& Paste", idm_paste end popup "& help ", 65535 begin menuitem "& about", idm_about endend

   

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.