Re: multiple language support: dialog-boxes
On 18 Jun., 20:41, Joseph M. Newcomer <newco...@flounder.com> wrote:
Why is there *any* button called "btn1". The FIRST thing you do when c=
reating controls is
change all those stupid default IDs (e.g., IDC_BUTTON1) to something mean=
ingful (e.g.
IDC_ASK_USER_FOR_NAME). Only then do you start to create variables (wh=
ich will have
meaningful names, like c_AskUserForName) and handlers (e.g., OnBnClickedA=
sUserForName).
So already you are digging yourself into a pit of unmaintainability.
On Fri, 18 Jun 2010 10:30:36 -0700 (PDT), mfc <mfcp...@googlemail.com> wr=
ote:
Hi,
I`ve a sdi application where I want to add multiple language support.
If the user press the button btn1, the language should be changed.
After the OnButtonClick-Function I`m using SendMessage to send a msg
to one function in the mainframe-class
(class CMainFrame : public CFrameWnd)
This is the function in the CMainFrame() - only a small demo:
HINSTANCE hInst = NULL;
if(!m_hInstGerman)
m_hInstGerman = LoadLibrary(_T("LangDeu.dll"));
****
There are so many things wrong with the above code I cannot hope to list =
all of them.
Why is there an m_hInstGerman? Do you plan to add a variable for each =
of the several
hundred languages supported? Will there be an hInstItalian_Italy, hins=
tItalian_Swiss, an
hInstSpanish_Mexican, an hInstFrench_Canadian? Of course not. One l=
ocal instance
variable will suffice for all possible languages and that's all you shoul=
d ever need. In
the worst case, using a simple std::map to map language abbreviations to =
DLL handles might
be used, if you want to support the user dynamically switching languages.=
Or, you can
compute the DLL name (GetModuleFileName) and only load the DLL if the nam=
e you get is
different from the one you have (don't forget to FreeLibrary the one you =
are about to
replace!)
Why are you not forming the name from the user's current selected active =
language? Why
did you hardwire it to "LangDeu.dll"?
Do you plan to add code like the above for each of the hundreds of langua=
ges supported by
Windows?
Play with my Locale Explorer (see my MVP Tips site). It will even generat=
e the code for
you!
From the Locale Explorer:
// LOCALE_SABBREVLANGNAME
CString sabbrevlangname_data;
LCID lcid = LOCALE_SYSTEM_DEFAULT;
{ /* get LOCALE_SABBREVLANGNAME */
LPTSTR p = sabbrevlangname_data.GetBuffer(4);
VERIFY(::GetLocaleInfo(lcid, LOCALE_SABBREVLANGNAME, p, 4));
sabbrevlangname_data.ReleaseBuffer();} /* get LOCALE_SABBREVLANGNAME *=
/
// ... use sabbrevlangname_data here
thanks for all these information. Do you know which steps I`ve to do
to start a new dll (during running the programm)? Or is it only
possible to restart the programm to start a new dll???
All the steps which are necessary after loading the new dll file with
LoadLibrary()...