Windows Mobile menu bar resource usage

Source: Internet
Author: User

Address: http://hi.baidu.com/banwusan/blog/item/ffa78dc31e897856b219a829.html

 

Menu Bar Resource

Menu bar is like a toolbar control in many aspects. View the resources used by the menu bar. The differences between the two objects are the appearance. Figure 5-7 shows a simple menu bar.
Figure 5-7 (Omitted): A simple menu bar that opens the edit menu.

When a menu bar is created, the ntoolbarid field in the shmenubarinfo structure is properly set, because the resource identified by ntoolbarid is not a menu resource, but a custom resource used for the menu bar control. To create the menu bar shown in Figure 5-7, the resource editor creates the following text in the. RC file:
//////////////////////////////////////// ///////////////////////////////////
// Data
//
Idm_menu shmenubar moveable pure
Begin
Idm_menu, 4,
I _imagenone, idm_sharednew, tbstate_enabled, tbstyle_autosize, ids_shnew,
0, nomenu,
I _imagenone , Id_edit, tbstate_enabled,
Tbstyle_dropdown | tbstyle_autosize, ids_cap_edit, 0, 0,
I _imagenone , Idm_main_command1, tbstate_enabled,
Tbstyle_dropdown | tbstyle_autosize, ids_help, 0, 1,
0, id_backbtn, tbstate_enabled, tbstyle_autosize, 0, id_backbtn, 2,
End

//////////////////////////////////////// ///////////////////////////////////
// Menu bar
//
Idm_menu menu discardable
Begin
Popup "edit"
Begin
Menuitem "cut", id_edit_cut
Menuitem "copy", id_edit_copy
Menuitem "Paste", id_edit_paste
End
Popup "Tools"
Begin
Menuitem "about", idm_help_about
Menuitem "options", id_tools_options
End
End

In most cases, you do not need to know exactly what resources the resource editor has placed in the resource. However, it is necessary to understand the format so that the menu bar application can be easily changed. Program You can also easily use it when the resource editor cannot create a menu bar control on the device you are using. The resource is actually the description of the buttons on the toolbar. The following Code The preceding data format is provided:
Idm_menu shmenubar moveable pure
Begin
Idm_menu, 4,

I _imagenon E, idm_sharednew, tbstate_enabled,
Tbstyle_autosize, ids_shnew, 0, nomenu,

I _imagenone , Id_edit, tbstate_enabled,
Tbstyle_dropdown | tbstyle_autosize, ids_cap_edit, 0, 0,

I _imagenone , Idm_main_command1, tbstate_enabled,
Tbstyle_dropdown | tbstyle_autosize, ids_help, 0, 1,

0, id_backbtn, tbstate_enabled,
Tbstyle_autosize, 0, id_backbtn, 2,
End

In the first line of the resource file, idm_menu is the resource ID, shmenubar is the resource type, and moveable and pure are the resource flags. Idm_menu must be passed as the ID to the shmenubarinfo structure of shcreatemenubar. The resource type shmenubar is actually defined as rcdata by the wizard. The resource compiler considers it as a simple resource data block used by the application. This is important because shmenubar is not defined in the include files file of the Pocket PC. Only the Pocket PC Application Wizard (Appwizard) is used) to create a menu bar. Therefore, for menu bar resource files generated by non-Wizard, add the following content to the RC file: # define shmenubar rcdata

The first line of data in the begin/end block is idm_menu, 4. This line defines menu resources for creating separate pop-up menus on the menu bar. Number 4 indicates the number of the item in the shmenubar resource. Each item is either a pop-up menu on the menu bar or a button.

Because of the book printing format, every description in the preceding Resource description is divided into two lines. Let's take a look at the last item in the resource -- back button item:
0, id_backbtn, tbstate_enabled, tbstyle_autosize, 0, id_backbtn, 2,

Vertically fold the row. After adding a comment, the resource description is as follows:

0, // bitmap Index
Id_backbtn, // wm_command id value
Tbstate_enabled, // initial state of "button"
Tbstyle_autosize, // style of "button"
0, // string resource ID of text label
Id_backbtn, // string resource ID of tooltip
2, // submenu Index

The index of the item on the menu bar in the bitmap array is included in the first domain. If this item does not have a bitmap, SetSet to I _imaGenone. In the above example, the image used is the first in the bitmap array. The next field contains the ID of the item. For a button, this value is the ID value sent to the parent window with the wm_command message when the button is clicked. You can use this ID to identify a sub-menu when querying the sub-menu handle. Because shell uses its own ID set in the menu bar, the application should not use a value smaller than 100. This rule applies to menus, buttons, and string resource IDs.

The menu bar uses two predefined menu item IDs: idm_sharednew and idm_sharednewdefault. These two IDs Add a new menu item to display the menu items registered by other applications. The difference between the two IDs is that, simply click the menu item, idm_sharednewdefault will display a new menu item. When idm_sharednew is used, the new menu is changed to a button with a drop-down arrow. Click the new button to send the wm_command message to the parent window, indicating that a new document should be created. Click the arrow to display the new menu. For non-Pocket PC systems, the new menu is displayed on the menu bar only when shell provides new menu support for the system. Otherwise, the predefined new menu item ID is ignored.

the following two fields are the initial status and style of the button/root menu item. The Status field uses the status flag of the toolbar for description, such as tbstate_enabled and tbstate_checked. For menus, the status is almost always tbstate_enabled. The style field is also described using the style icon of the toolbar. For example, the tbstyle_button used for the button is used for the tbstyle_dropdown of the menu item. Items with text instead of Bitmap and items containing bitmap are usually configured with tbstyle_autosize to tell the menu bar to adjust the button size to adapt to the text in the menu item.

the next field is the string resource ID of the menu item text. Text is placed side by side with the image specified in the first domain. In the above example, this item is just a simple bitmap button, so no string resource is specified. For a menu item, it is a string resource to mark the menu, rather than the sub-menu name specified in the menu resource. If necessary, you can use seven predefined string IDs, which are defined in aygshell. h as self-explanatory constants.
# define ids_shnew 1
# define ids_shedit 2
# define ids_shtools 3
# define ids_shview 4
# define ids_shfile 5
# define ids_shgo 6
# define ids_shfavorites 7
# define ids_shopen 8
if you need a different text, then your application must use the string resource definition text and pass the ID to this domain. The next domain is the tooltip domain. Similarly, you must use the string resource ID to fill this field.

The last field specifies the sub-menu. When you click this item, it will pop up. This sub-menu value is valid only when the style field contains the tbstyle_dropdown flag (indicating that a menu is attached to the item. This value indicates the menu resource index of the sub-menu. In this example, there are two sub-menus: the edit menu (eidt), which includes cut, copy and paste menu items; the Tools menu, contains two menu items: About and options. The text displayed on the button is from the menu bar resource rather than from the menu resource. For example,

You can click the following code to modify menu resources without changing the text in the menu bar.
//////////////////////////////////////// ///////////////////////////////////
// Menu bar
//
Idm_menu menu discardable
Begin
Popup "cat"
Begin
Menuitem "cut", id_edit_cut
Menuitem "copy", id_edit_copy
Menuitem "Paste", id_edit_paste
End
Popup "dog"
Begin
Menuitem "about", idm_help_about
Menuitem "options", id_tools_options
End
End
Now, the root menu name is cat and dog, rather than edit and options. Because the menu bar is named from the menu bar, rather than from the menu resource, this change does not affect the application.

A long description of a menu bar gives you basic knowledge. Manual resource manipulation is required only in rare cases. Of course, this knowledge is easy to use.

Related Article

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.