Various resources in
English and in French
   Language specific strings
Various resources in English and French
Here the resource file makes two dialogs, two menus, and
two raw data strings (RCDATA) with the same IDs but in two
different languages.
The API FindResourceEx, which is language specific, loads the correct
resources, depending on the value of TEST_LANGUAGE. This value is set
either to 809h (English, UK) or 140Ch (French, Luxembourg) depending on
which test is being carried out.
The breakpoints RESOURCESIN_ENGLISH and RESOURCESIN_FRENCH show
how the dialog is made. The breakpoint LANG_RESOURCETEST is called
on the message WM_INITDIALOG in the MDLangDlgProc dialog procedure
and loads the correct menu and raw data strings to write inside the
dialog.
First lets look at the resource file itself (note this is syntax
acceptable to GoRC, and will need changing for RC):-
;************** the English menu
200h MENU
LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_UK
BEGIN
MENUITEM "this", 0x0FFFC
MENUITEM "menu", 0x0FFFD
MENUITEM "does", 0x0FFFE
MENUITEM "nothing", 0x0FFFF
END
;************** now the French menu
200h MENU
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH_LUXEMBOURG
BEGIN
MENUITEM "cet", 0x0FFFC
MENUITEM "menu", 0x0FFFD
MENUITEM "ne fait", 0x0FFFE
MENUITEM "rien", 0x0FFFF
END
;************** the English dialog
LangDlg DIALOG 10, 10, 160, 80
FONT 8,"MS Sans Serif"
CAPTION "Language test dialog"
LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_UK
BEGIN
ICON 1, -1, 8, 8, 0, 0
CTEXT "English version of this dialog", -1, 30,12,100, 8
CTEXT "", 0x200, 0, 28,160, 8
DEFPUSHBUTTON "OK", 1,102,50, 50,14
END
;************** the French dialog
LangDlg DIALOG 10, 10, 160, 80
FONT 8,"MS Sans Serif"
CAPTION "Le dialog pour le test \340 langage"
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH_LUXEMBOURG
BEGIN
ICON 1, -1, 8, 8, 0, 0
CTEXT "Version francais de cet dialog", -1, 30,12,100, 8
CTEXT "", 0x200, 0, 28,160, 8
DEFPUSHBUTTON "accord", 1,102,50, 50,14
END
;************** the English raw data
LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_UK
0x200 RCDATA
BEGIN
"This is an English raw data string\0"
END
;************** the French raw data
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH_LUXEMBOURG
0x200 RCDATA
BEGIN
"Ici un string francais data raw\0"
END
Now this is how the dialog is made:-
RESOURCESIN_ENGLISH:
MOV D[TEST_LANGUAGE],0809h ;ENGLISH, UK
JMP >L2
RESOURCESIN_FRENCH:
MOV D[TEST_LANGUAGE],140Ch ;FRENCH, LUXEMBOURG
L2:
PUSH [TEST_LANGUAGE]
PUSH 'LangDlg'
PUSH 5 ;DIALOG (5)
PUSH [hInst]
CALL FindResourceExA ;find language-specific resource
OR EAX,EAX ;see if failed
JZ >L5 ;yes
PUSH EAX,[hInst]
CALL LoadResource
PUSH 0,OFFSET MDLangDlgProc,[hWnd]
PUSH EAX,[hInst]
CALL DialogBoxIndirectParamA
L5:
RET
And this loads the other resources on WM_INITDIALOG:-
LANG_RESOURCETEST:
PUSH [TEST_LANGUAGE]
PUSH 200h
PUSH 4 ;MENU type (4) ;FindResource
PUSH [hInst]
CALL FindResourceExA ;find language-specific resource
OR EAX,EAX
JZ >L2
PUSH EAX,[hInst]
CALL LoadResource
PUSH EAX
CALL LoadMenuIndirectA ;get handle
PUSH EAX,[EBP+8]
CALL SetMenu
L2:
PUSH [TEST_LANGUAGE]
PUSH 200h,10,[hInst] ;ID, RCDATA type (10)
CALL FindResourceExA ;find language-specific resource
PUSH EAX,[hInst]
CALL LoadResource
PUSH EAX,0,0Ch,200h,[EBP+8] ;text,, WM_SETTEXT, itemID
CALL SendDlgItemMessageA
MOV EAX,1 ;message processed
Language specific string
In this test we don't use a language specific API to load
the resource. This means that if there are different language versions of
the specified resource, the one loaded will depend on the current language setting in Control panel (the nearest will be loaded).
The correct string is loaded into BUFFER and displayed in a message
box. Use the breakpoint STRINGTABLES_BY_LANGUAGE.
STRINGTABLES_BY_LANGUAGE: ;demonstrates how different strings can be obtained
PUSH 256D,ADDR BUFFER,8888h,[hInst]
CALL LoadStringA ;get correct string depending on current language
PUSH 40h ;information+ok button only
PUSH ADDR SMESS1
PUSH ADDR BUFFER
PUSH [hWnd]
CALL MessageBoxA ;wait till ok pressed
RET
This is what is in the resource file (GoRC syntax). Note that the same
ID is used in each case:-
STRINGTABLE
LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_UK
BEGIN
0x8888 "A string with an ID of 8888h has been obtained by LoadString.
Now using the control panel, change to French(Luxembourg),
and come back here to see a string with the same ID
but in French! (Don't bother to reboot)."
END
;******
STRINGTABLE
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH_LUXEMBOURG
BEGIN
0x8888 "Je te l'avais bien dit!"
END