How to change software UI Language

Source: Internet
Author: User

Recently, I mastered a method on how to change software UI language such as menu, button something like that. here, I wirte something for you and share my code with you. if you like it. we can talk about it together and exchange our mind each other. OK?

First of all, I will introduce to you abou menu resource and how to use it to translate language. as all of you know, menu resource play a important role in developing software, we must master it and then we will do something that we want to do. maybe you can understand what I just have said.

Using editor context to open RC file and you will see something as following description:
// Menu
//

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 "latest file", id_file_mru_file1, grayed
Menuitem Separator
Menuitem "exit (& X)", id_app_exit
End
Popup "Edit (& E )"
Begin
Menuitem "undo (& 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 "language", id_languagemenu
End
Popup "Help (& H )"
Begin
Menuitem "about menubground (& A)...", id_app_about
End
End

Translate them like this:

Idr_english menu 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 "printview (& V)", id_file_print_preview
Menuitem "printset (& 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 "undo (& 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 "Look (& V )"
Begin
Menuitem "toolbar (& T)", id_view_toolbar
Menuitem "statusbar (& S)", id_view_status_bar
Menuitem "language", id_languagemenu
End
Popup "Help (& H )"
Begin
Menuitem "about menubground (& A)...", id_app_about
End
End

And then, save them. You just completed the step one. The next task is about how to associate with software UI.

You shoshould return Resource Manager and Open menu item, you will see another menu idr_engish.add the same ID for idr_english and idr_mainframe like the following picture:

The two menus:
Chinese:


English:

Pay attention to language and "language", you must use the same ID. And then you will response menu function such as language or "language" as following Code Description:

Int cmainframe: oncreate (maid)
{
If (cframewnd: oncreate (lpcreatestruct) =-1)
Return-1;
 
If (! M_wndtoolbar.createex (this, tbstyle_flat, ws_child | ws_visible | cbrs_top
| Cbrs_gripper | cbrs_tooltips | cbrs_flyby | cbrs_size_dynamic) |
! M_wndtoolbar.loadtoolbar (idr_mainframe ))
{
Trace0 ("failed to create toolbar/N ");
Return-1; // fail to create
}

If (! M_wndstatusbar.create (this) |
! M_wndstatusbar.setindicators (indicators,
Sizeof (indicators)/sizeof (uint )))
{
Trace0 ("failed to create status bar/N ");
Return-1; // fail to create
}

// Todo: delete these three lines if you don't want the toolbar
// Be dockable
M_wndtoolbar.enabledocking (cbrs_align_any );
Enabledocking (cbrs_align_any );
Dockcontrolbar (& m_wndtoolbar );

M_english.loadmenu ("idr_english"); // Add an English menu resource
Hmenu =: getmenu (this-> m_hwnd); // obtain Chinese menu Resources
M_chinese.attach (hmenu); // save Chinese menu Resources

// About cmenu Bar background color information

Return 0;
}

Respose function for translation language like this:

Xxx. h:

Class cmainframe: Public cframewnd
{
 
Protected: // create from serialization only
Cmainframe ();
Declare_dyncreate (cmainframe)

// Attributes
Public:

// Operations
Public:

// Overrides
// Classwizard generated virtual function overrides
// {Afx_virtual (cmainframe)
Virtual bool precreatewindow (createstruct & CS );
//} Afx_virtual

// Implementation
Public:
Virtual ~ Cmainframe ();
# Ifdef _ debug
Virtual void assertvalid () const;
Virtual void dump (cdumpcontext & DC) const;
# Endif

Protected: // control bar embedded members
Cstatusbar m_wndstatusbar;
Ctoolbar m_wndtoolbar;
Cbrush m_wndbrush;
Bool isenglish;
Cmenu m_chinese;
Cmenu m_english;

// Generated message map Functions
Protected:
// {Afx_msg (cmainframe)
Afx_msg int oncreate (maid );
Afx_msg void onreceivagemenu ();
//} Afx_msg
Declare_message_map ()
};

 

Xxx. cpp:

Begin_message_map (cmainframe, cframewnd)
// {Afx_msg_map (cmainframe)
On_wm_create ()
On_command (id_1_agemenu, on1_agemenu)
//} Afx_msg_map
End_message_map ()

 

Void cmainframe: onreceivagemenu ()
{
// Todo: add your command handler code here
Isenglish =! Isenglish;
If (isenglish)
{
This-> setmenu (& m_english );
}
Else
{
This-> setmenu (& m_chinese );
}
}

In the end. You have finished it.

 

 

 

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.