15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Using international string resources in dialog design

TA -- siemens@inet.uni-c.dk
Friday, January 17, 1997

Environment: VC++ 4.0, Windows NT 4.0

I wish to use string resources for the controls on my dialogs. How can I
set these with a minimal effort?
Is it really necessary to use API's like LoadString() and SetWindowText()?

There must be a way to automate this proces!

Thanks in advance and best regards,

Kent Fonager
kfk@siemens.dk
Siemens A/S
Borupvang 3
DK-2750 Ballerup
+45 4477 5934



Brad Wilson/Crucial Software -- crucial@pobox.com
Saturday, January 18, 1997

[Mini-digest: 6 responses]

> Environment: VC++ 4.0, Windows NT 4.0
> 
> I wish to use string resources for the controls on my dialogs. How can I
> set these with a minimal effort?

The only advantage I see to using strings to set the text on dialog
controls is that the string is used in many places (internationalize one
vs. many).  Otherwise, why are you doing this?

> Is it really necessary to use API's like LoadString() and
SetWindowText()?

Yes.

--
Brad Wilson, Objectivist   crucial@pobox.com   http://www.thebrads.com/

"No, his mind is not for rent . To any god or government
 Always hopeful, but discontent . He knows changes aren't permanent
 But change is..."    - Tom Sawyer (from the Rush CD "Moving Pictures")

-----From: Michael Iles 

On Friday, January 17, 1997 6:51 AM, Siemens, 
TA[SMTP:siemens@inet.uni-c.dk] wrote:
>Environment: VC++ 4.0, Windows NT 4.0
>
>I wish to use string resources for the controls on my dialogs. How 
can I
>set these with a minimal effort?
>Is it really necessary to use API's like LoadString() and 
SetWindowText()?

Hi Kent,

The text used on your dialogs is also in your .rc file, so you can 
localise it as easily as you localise your string resources.

Mike.

-----From: Sergei Fishel 

First you should do is to install another language system for your NT.
So, if you install German as primary language you will see that
resources will appear with German code page when you will create
them. This is primary way.

Second way, is to edit manually resource file and put there 
reference to German code page. (But you should have it installed
already any way).

I have example with Russian language, but it uses default code page
and sub-language. You will have to replace code page to German one and 
sublang as well.

////////////////////////////////////////////////////////
// Russian resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32


Regards


At 12:51 PM 1/17/97 +0100, you wrote:
>Environment: VC++ 4.0, Windows NT 4.0
>
>I wish to use string resources for the controls on my dialogs. How can I
>set these with a minimal effort?
>Is it really necessary to use API's like LoadString() and SetWindowText()?
>
>There must be a way to automate this proces!
>
>Thanks in advance and best regards,
>
>Kent Fonager
>kfk@siemens.dk
>Siemens A/S
>Borupvang 3
>DK-2750 Ballerup
>+45 4477 5934
>

-----From: Tim Robinson 

At 12:51 1/17/97 +0100, you wrote:
>Environment: VC++ 4.0, Windows NT 4.0
>
>I wish to use string resources for the controls on my dialogs. How can I
>set these with a minimal effort?
>Is it really necessary to use API's like LoadString() and SetWindowText()?
>
>There must be a way to automate this proces!

Offhand, I should point out that dialogs ARE localizable resources just like
strings.  In theory, there shouldn't be a need to automate a relation
between a dialog and a string resource.  Any translator should do the
dialogs just like doing the strings.  However, if you're bent on doing that,
why not something like the following in your OnInitDialog:

static struct {
   int m_ID, m_String;
   } tab[] = {
   { IDC_STATIC1, IDS_STRING1 },
   { IDC_STATIC2, IDS_STRING2 },  // etc...
   { 0, 0 } };
CString text;
for ( int i=0; tab[i].m_ID; i++ ) {
   text.LoadString (tab[i].m_String );
   ((CWnd*)GetDlgItem( tab[i].m_ID )->SetWindowText( text );
   }

Untested, but that's as painless as I can imagine.  Naturally, consider
subclassing CDialog if you're going to use this a bunch of places.

| Tim Robinson, Esquire          | Liberty  means responsibility. |
| timtroyr@ionet.net             | That is why most men dread it. |
| http://www.ionet.net/~timtroyr |            George Bernard Shaw |

-----From: "Hemanta Banerjee" 

> I wish to use string resources for the controls on my dialogs. How can I
> set these with a minimal effort?
> Is it really necessary to use API's like LoadString() and
SetWindowText()?
There cannot be an automatic way of doin it. The only semi automatic way of
doing whereby u can give the notion of automatic handling is :- 

1) Define strings in ur string table. 
2) In the string table add an entry for the dialog in the form 
dialog name,start string table pos, number of entries and have the position
as some factor of the dialog id. (like dialog id * 3 + 100 - blah blah
....) so that u have a unique position for the entry. 
3) Have a common base class derived from CDialog which in its init dialog
will load the string and do corresponding activities. Here u have to take
care bcos u cannot just have entries for text fields. U also have to have
entries for list boxes, combo's etc. 

So have a schema like this 
Field id, type , no of strings , string entries separated by commas . 
So if ur type is combo then load all the strings and do needful etc. 

But even this is not automatic but all dialogs need not repeat the code. It
is just reusability. 

Bye
Hemanta
-----From: "Christian Rosner" 

Kent Fonager wrote:

> I wish to use string resources for the controls on my dialogs. How can I
> set these with a minimal effort? Is it really necessary to use API's like
> LoadString() and SetWindowText()?
> 
> There must be a way to automate this proces!

Yes: inheritance!

I inherited a subclass from the MFC classes CFormView and CDialog and
called a function Translate() from within the function
CFormView::OnInitialUpdate() (resp. CDialog::OnInitDialog()). The function
Translate() simply iterates through each control in the form (using
EnumChildWindows()) and loads for each control the label string from the
resources (identified by the control ID) and sets the new window text.

Now you can use the new class instead of the MFC class and the translation
is done automatically. 

If you need more help (or some sample code) please write me an email.

Hope this helps

Christian

----------
Christian Rosner (crosner@csci.csc.com)




Alexey Yakovlev -- avy@aha.ru
Tuesday, January 21, 1997

Environment: MSVC 4.2b Win95 WinNT 4.0


Sergei Fishel  wrote:

> ////////////////////////////////////////////////////////
> // Russian resources

> #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
> #ifdef _WIN32
> LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
> #pragma code_page(1251)
> #endif //_WIN32


...it is all nice and fine:

You can have your resources in 2 (or more) languages attached 
right to your executable. No need for fancy dialog processing,
substituting strings from resources or loading language DLLs.

Just create a copy of resource (VC will mark it as ID_NAME1), 
switch it to different language and change ID back to original
ID_NAME. Then you can edit such resources in VC editor after 
selecting required input locale in WinNT control panel. 

WinNT will use your custom accelerators and display your menus,
dialogs and strings at runtime based on the locale selected by 
user. Very cool, very convenient, single binary for all 
international users, bravo Microsoft!  

BUT it does not work in English version of Win95. I have English
(United States) and Russian locales and fonts installed, and can 
successfully type using both languages in MS Word, for example. 

Win95 shows _English version_ of resource regardless of what is 
in international settings. When I remove all but Russian language 
resources, Win95 displays underlines instead of my cyrillic chars. 
A _recompile under Win95 with #pragma code_page(1251) commented 
out_ is needed to make this exe show correctly under Win95. BUT 
then cyrillic will show up as question marks on WinNT...

Any ideas? Can RC mark the executable for Russian (or whatever 
alternate language to be displayed correctly on _both_ Win32 
platforms?


Alexey
-- 
avy@aha.ru
http://win.aha.ru/~avy    (Russian cp1251)




Alexey Yakovlev -- avy@aha.ru
Tuesday, January 21, 1997

Environment: MSVC 4.2b Win95 WinNT 4.0


Sergei Fishel  wrote:

> ////////////////////////////////////////////////////////
> // Russian resources

> #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
> #ifdef _WIN32
> LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
> #pragma code_page(1251)
> #endif //_WIN32


...it is all nice and fine:

You can have your resources in 2 (or more) languages attached 
right to your executable. No need for fancy dialog processing,
substituting strings from resources or loading language DLLs.

Just create a copy of resource (VC will mark it as ID_NAME1), 
switch it to different language and change ID back to original
ID_NAME. Then you can edit such resources in VC editor after 
selecting required input locale in WinNT control panel. 

WinNT will use your custom accelerators and display your menus,
dialogs and strings at runtime based on the locale selected by 
user. Very cool, very convenient, single binary for all 
international users, bravo Microsoft!  

BUT it does not work in English version of Win95. I have English
(United States) and Russian locales and fonts installed, and can 
successfully type using both languages in MS Word, for example. 

Win95 shows _English version_ of resource regardless of what is 
in international settings. When I remove all but Russian language 
resources, Win95 displays underlines instead of my cyrillic chars. 
A _recompile under Win95 with #pragma code_page(1251) commented 
out_ is needed to make this exe show correctly under Win95. BUT 
then cyrillic will show up as question marks on WinNT...

Any ideas? Can RC mark the executable for Russian (or whatever 
alternate language to be displayed correctly on _both_ Win32 
platforms?


Alexey
-- 
avy@aha.ru
http://win.aha.ru/~avy    (Russian cp1251)




Kristoffer -- gjevre@filenet.com
Wednesday, January 22, 1997

According to the "Developing International Software" by Nadine Kano, on 
Windows NT, most standard resource calls retrieve resources based on the 
language ID of the calling thread locale, and only Windows NT supports 
SetThreadLocale and GetThreadLocale, and another method has to be used for 
Windows 95 to change the user interface at run time (Page 136).  From this 
it sounds like you can not get to other than the default language resources 
on Windows 95.

Kristoffer

----------
From:  Alexey Yakovlev[SMTP:avy@aha.ru]
Sent:  Monday, January 20, 1997 21:04
To:  mfc-l@netcom.com
Subject:  Re: Using international string resources in dialog design

Environment: MSVC 4.2b Win95 WinNT 4.0


Sergei Fishel  wrote:

> ////////////////////////////////////////////////////////
> // Russian resources

> #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
> #ifdef _WIN32
> LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
> #pragma code_page(1251)
> #endif //_WIN32


...it is all nice and fine:

You can have your resources in 2 (or more) languages attached
right to your executable. No need for fancy dialog processing,
substituting strings from resources or loading language DLLs.

Just create a copy of resource (VC will mark it as ID_NAME1),
switch it to different language and change ID back to original
ID_NAME. Then you can edit such resources in VC editor after
selecting required input locale in WinNT control panel.

WinNT will use your custom accelerators and display your menus,
dialogs and strings at runtime based on the locale selected by
user. Very cool, very convenient, single binary for all
international users, bravo Microsoft!

BUT it does not work in English version of Win95. I have English
(United States) and Russian locales and fonts installed, and can
successfully type using both languages in MS Word, for example.

Win95 shows _English version_ of resource regardless of what is
in international settings. When I remove all but Russian language
resources, Win95 displays underlines instead of my cyrillic chars.
A _recompile under Win95 with #pragma code_page(1251) commented
out_ is needed to make this exe show correctly under Win95. BUT
then cyrillic will show up as question marks on WinNT...

Any ideas? Can RC mark the executable for Russian (or whatever
alternate language to be displayed correctly on _both_ Win32
platforms?


Alexey
--
avy@aha.ru
http://win.aha.ru/~avy    (Russian cp1251)




| Вернуться в корень Архива |