---- With the development of the Internet, the internationalization of software is inevitable. A software may be used by people in many countries, such as adding multiple languages.
The menu of words, not only brings a lot of convenience to the user, but also has a lot of convenience to the promotion of your software. For example, give you the Chinese software, plus one
English or Japanese menus will bring a lot of convenience to friends who are English and Japanese. The multilingual menu implemented in the VC is very easy.
Take a way for examples of the multilingual menu implementation.
---- First, establish an engineering project document
---- Establish an engineering project with the AppWizard in VC: MENU. In the alternative item, the elector's single document, language is Chinese,
The rest of the elevator default. At this time, the compilation is run to get an application with a Chinese menu. The English menu will be added to the application.
---- Second, modify the establishment of menu resources
---- Open the menu resource editor in the resource editor to edit the IDR_MAINFRAME menu resource, add the switch command item for changing the menu. View item
Take the menu:
---- ID: ID_MENU_CHANGE CAPTION English (& E)
---- Close the resource editor. Use the resource files under Windows to open the resource file menu.rc find the following:
IDR_MAINFRAME MENU PRELOAD DISCARDABLE
Begin
Popup "file (& f)"
Begin
MenuItem "New (& N) / TCTRL N", ID_FILE_NEW
Menuitem "Open (& O) ... / TCTRL O", ID_FILE_OPEN
Menuitem "Save (& S) / TCTRL S", ID_FILE_SAVE
Menuitem "Save As (& A) ...", ID_FILE_SAVE_AS
Menuitem Separator
Menuitem "Print (& P) ... / TCTRL P", ID_FILE_PRINT
Menuitem "Print Preview (& V)", ID_FILE_PRINT_PREVIEW
MenuItem "Print Settings (& R) ...", ID_FILE_PRINT_SETUP
Menuitem Separator
MenuItem "Recent File", ID_FILE_MRU_FILE1, GRAYED
Menuitem Separator
MenuItem "Exit (& X)", ID_APP_EXIT
End
POPUP "Edit (& E)"
Begin
MenuiteM "Cancel (& U) / TCTRL Z", ID_EDIT_UNDO
Menuitem Separator
Menuitem "Cut (& T) / TCTRL X", ID_EDIT_CUT
MenuItem "Copy (& C) / TCTRL C", ID_EDIT_COPY
Menuitem "Paste (& P) / TCTRL V", ID_EDIT_PASTE
End
POPUP "View (& V)"
Begin
Menuitem "Toolbar (& T)", ID_View_toolbar
Menuitem "Status Bar (& S)", ID_View_status_bar
Menuitem "English", ID_MENU_CHANGE
End
POPUP "Help (& H)"
Begin
MenuItem "About Menu (& A), ID_APP_ABoutend
End
---- Copy the above content into the clipboard and copy one part to the above, and partially modified. Change IDR_MAINFRAME to
IDR_MAINFRAME_EN, other Chinese translated into English and modified by the habit of the English menu. The changed menu resources are as follows:
IDR_MAINFRAME_EN MENU PRELOAD DISCARDABLE
Begin
Popup "& file"
Begin
Menuitem "New (& N) / TCTRL N", ID_FILE_NEW
Menuitem "Open (& O) ... / TCTRL O", ID_FILE_OPEN
Menuitem "Save (& S) / TCTRL S", ID_FILE_SAVE
Menuitem "Save As (& A) ...", ID_FILE_SAVE_AS
Menuitem Separator
Menuitem "& Print ... / TCTRL P", ID_FILE_PRINT
Menuitem "Print Pre & View", ID_FILE_PRINT_PREVIEW
Menuitem "& Printer Reset ...", ID_FILE_PRINT_SETUP
Menuitem Separator
Menuitem "Re ¢ File", ID_FILE_MRU_FILE1, GRAYED
Menuitem Separator
Menuitem "E (& X) IT", ID_APP_EXIT
End
POPUP "& E) DIT"
Begin
Menuitem "& undo / tctrl z", id_edit_undo
Menuitem Separator
Menuitem "Cu & T / TCTRL X", ID_EDIT_CUT
Menuitem "& Copy / TCTRL C", ID_EDIT_COPY
Menuitem "& Paste / TCTRL V", ID_EDIT_PASTE
End
POPUP "& view"
Begin
Menuitem "& Tool Bar", ID_View_toolbar
Menuitem "& status bar", id_view_status_bar
Menuitem "& Chinese", ID_MENU_CHANGE
End
Popup "& Help"
Begin
Menuitem "& About Menu ...", ID_APP_ABOUT
End
End
---- Save the modified resource file. Re-transfer the resource file into the resource editor, you can find that there are two menu resources. If there is any discomfort
Make further modifications in the resource editor.
---- Third, join the menu variable to the program
---- Since the menu is attached to the main window, the related variables should be added to the CMAINFRAME class:
PUBLIC:
Cmenu m_penglish; // Used to save English menu resources
CMenu m_pchinese; // Used to save Chinese menu resources
Enum {c, e} m_emenu; // Today is English now
Menu or Chinese menu, c - Chinese, e-English
---- Fourth, the initialization variable needs to initialize the variable only one m_emenu. Since the startup menu uses the default Chinese menu, initialize in the CMAINFRAME constructor:
CMAINFRAME :: CMAINFRAME ()
{
// Todo: Add Member Initialization Code Here
M_Menu = C;
}
---- Five, transfer to save menu resources
---- In the oncreate function in the main window, initialize and save the menu resources:
INT CMAINFRAME :: OnCreate (lpcreatestruct lpcreatestruct)
{
.......
M_PENGLISH.LOADMENU (idR_mainframe_en); // Turn English menu resources
HMENU HM = :: getMenu (this-> m_hwnd); // Get Chinese menu resources
m_pchinese.attach (hm); // Save Chinese Menu Resources
Return 0;
}
---- 6. Response change menu command
---- Use ClassWizard to join the ID_MENU_CHANGE menu command response function for the CMAINFRAME class:
Void CMAINFRAME :: onMenuchange ()
{
// Todo: add your command handler code here
IF (m_menu == e) // If the menu is now English
{
SetMenu (& M_PCHINESE); // Set the menu to Chinese
M_Menu = C;
}
Else if (m_menu == c) // If the menu is now Chinese
{
SetMenu (& M_PENGLISH); // Setting the menu for English
m_menu = e;
}
}
---- Seven, destroy menu
---- Destroy the menu in the Qian Qian 's CMAINFRAME:
CMAINFRAME :: ~ cmainframe ()
{
m_pchinese.destroymenu ();
M_PENGLISH.DESTROYMENU ();
}
---- Compilation Run program You can get an application with English-Chinese control menu.
---- Eight, conclude
---- The above example is only given the menu of two languages, but it is easy to reproduce the application of multilingual menu. Since the various language menus are actually
Different menu resources, so in the same application, you can use different menus. If the user registered in the shared software uses a menu, not noted
The user of the volume uses another menu without having to issue multiple versions and multiple installations, making registration easy and get more software.