Multi-language menu via ini

Source: Internet
Author: User

I have read the VC knowledge base from the previous article "Implementing multilingual Menus"Article. The method used in that article is to define two menus in the resource, one in English and one in Chinese...

IfProgramIt is very inappropriate to use that method to build a language of 100 countries. The reason is that the software author cannot speak 100 languages... the most important thing is that it is very inconvenient!

The best way is to save the menu to the INI file and define the menu by the user (change it to whatever you want ).

In the following 111222, I tried to use the INI storage menu for a demonstration project. By modifying menu items through INI, you can easily modify the language and content of the menu. More importantly, you can hand over the work to enthusiastic users .... of course, this is just a simple implementation, and there are two problems, I hope you can help me improve it.

First, you must be familiar with the functions of cmenu to modify the menu items.


Getmenuitemcount ();
// Obtain the number of menu items

Getmenuitemid (unit I );
// Obtain the ID of menu item I. Here, Id 0 indicates the split line, and-1 indicates the popup menu item.

Getmenustring (uint niditem, cstring & rstring, uint nflags );
// Obtain the string of the menu item

Modifymenu (uint nposition, uint nflags, uint nidnewitem = 0, lpctstr lpsznewitem = NULL );
// Modify the menu item. Here we mainly modify 4th parameters to change the text of the menu.

Next, I wrote a function to recursively traverse all menu items and modify the menu items according to the settings of the INI file:

// Function declaration mainfrm. h
Void initmenu (cmenu * menu );

//////////////////////////////////////// /////////
// Function: multi-language menu mainfrm. cpp
// Principle: traverse the menu items and replace the text of the menu items with the corresponding values in the INI file.
/// By 111222 August 1, September 13
//////////////////////////////////////// /////////
Void cmainframe: initmenu (cmenu * menu)
{
If (menu = NULL)
Return;
Int ncount = menu-> getmenuitemcount (); // gets the number of menus for this layer.
For (INT I = 0; I <ncount; I ++) // traverses all menu items
{
Int id = menu-> getmenuitemid (I); // View menu attributes. ID = 0 indicates the split line, and-1 indicates the popup menu.
If (ID = 0)
{}
Else if (ID =-1)
{
Cstring strtext;
Menu-> getmenustring (I, strtext, mf_byposition); // obtain the menu text
Cstring cs = afxgetapp ()-> getprofilestring ("menu", strtext, strtext); // read the text of the menu item in ini
Menu-> modifymenu (I, mf_string | mf_byposition, ID, CS );


// The following line is optional. Use this line to avoid manual ini editing and comment out the released version.
Afxgetapp ()-> writeprofilestring ("menu", strtext, CS );

Cmenu * psub = menu-> getsubmenu (I );
Initmenu (psub); // recursion, traversing the popup menu
}
Else
{
Cstring strtext;
Menu-> getmenustring (I, strtext, mf_byposition );
Cstring cs = afxgetapp ()-> getprofilestring ("menu", strtext, strtext );
Menu-> modifymenu (I, mf_string | mf_byposition, ID, CS );


// The following line is optional. Use this line to avoid manual ini editing and comment out the released version.
Afxgetapp ()-> writeprofilestring ("menu", strtext, CS );
}
}
}

Function call:

In cmainframe: OnAdd in create

// Multi Language menu
Cmenu * pmenu = getmenu ();
Initmenu (pmenu );

Now the multi-language menu through INI is complete.
For details, see the demo program.

The text of each menu item is stored in menu. You only need to modify the value to change the menu language.

Limitations of the above program:

Failed to modify the text of prompt (that is, the prompt displayed on the status bar)
The shortcut key is not displayed (New \ tctrl N in the menu will be abnormal)

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.