News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

When to use STRINGTABLE?

Started by hfheatherfox07, April 24, 2012, 10:02:37 PM

Previous topic - Next topic

hfheatherfox07

Hi there,

I was wondering when to use  a STRINGTABLE in the rsrc.rc as oppose to just adding the string in the .data section and why?
Other than pull down menu or tool tip is there any other examples of the use of STRINGTABLE in the rsrc.rc

Thank you

dedndave

i think it makes it easier to handle unicode strings
when you define a string in resource, it is unicode, by default

this is also true for menu text
i have written code to create a menu, and cut the size (for the menu) almost in half

NoCforMe

String tables are also used when a program needs to be "internationalized" (i.e., support different languages).

I still haven't been able to think of a single reason why I would want to use them in my own code.

dedndave

internationalization is what unicode strings are all about
and - i would like to make apps that support several languages

however - the ability to display Chinese characters (for example) does not mean i understand Chinese   :lol

jj2007

They are handy for building multilingual apps, see attachment (a MasmBasic template). For more complex apps, a Unicode text file is even better, though.

QuoteUse strings with e.g. Print Res$(101) or wPrint #1, wRes$(102) (w=wide, Unicode)
Note that in order to avoid bloated sections, strings should be incremented by 1, and start with indices that can be divided
by 16, as shown below (400/16=25, 800/16=50 etc).

STRINGTABLE
BEGIN
   001,   "Enter text here"         ; e.g. for ToolTips hEdit=wRes$(1+400*MyLanguage)
   002,   "Click on this button"   ; e.g. for wSetWin$ hButton=wRes$(2+400*MyLanguage)
   003,   "Welcome"
   401,   "Введите текст  здесь"   ; "Enter text here" in Russian
   402,   "Нажмите на эту кнопку"   ; "Click on this button" in Russian
   403,   "Добро пожаловать"   ; "Welcome" in Russian
   801,   "أدخل النص هنا"               ; "Enter text here" in Arabic
   802,   "دفع هذا الزر"                  ; "Click on this button" in Arabic
   803,   "مرحبا بكم"                  ; "Welcome" in Arabic
   1201,   "在這裡輸入文字"      ; "Enter text here" in Chinese
   1202,   "按一下這個按鈕"      ; "Click on this button" in Chinese
   1203,   "歡迎"                     ; "Welcome" in Chinese
;    Try wMsgBox 0, wRes$(402), wChr$("Wow:")
END

hfheatherfox07

I have seen an example were they were use to update a listbox as processes were done .... like showing on the status bar when you hover over a button but instead it printed in a list box...
any idea how that was done? with out masmbasic

dedndave

getting a string from resource is easy enough
the mouse-hover thing is the hard part - lol

LoadString,hInstance,IDS_STRINGID,offset szBuffer,(sizeof Buffer)/2
SendMessage,hListBox,LB_ADDSTRING,NULL,offset szBuffer

of course, you will want to use the unicode version of the functions
and - i guess the ListBox has to be unicode, too   :bg

xandaz

   using string tables or any other types of resources have the incovinient of obligating the programmer to know or to take notes of the identifiers of each string which is a drag. its much easier when fa: you call "Hello world",0 szHelloW or whatever.

jj2007

Quote from: xandaz on April 25, 2012, 10:10:05 PM
   using string tables or any other types of resources have the incovinient of obligating the programmer to know or to take notes of the identifiers of each string which is a drag. its much easier when fa: you call "Hello world",0 szHelloW or whatever.

Try changing the language of an app on the fly with that approach. See TheLang in the source attached to post #4 for an elegant solution.

dedndave

i think Jochen has the right idea - load it from a file
in fact, you could make it an easily edited unicode version of an INI type file
instead of getting someone to translate or trying to learn more languages than you'll use in a lifetime...
let them name the buttons whatever they like, in their own language   :P
oh - and give them an RTL option   :U

hfheatherfox07

Quote from: dedndave on April 25, 2012, 03:45:44 AM
getting a string from resource is easy enough
the mouse-hover thing is the hard part - lol

LoadString,hInstance,IDS_STRINGID,offset szBuffer,(sizeof Buffer)/2
SendMessage,hListBox,LB_ADDSTRING,NULL,offset szBuffer

of course, you will want to use the unicode version of the functions
and - i guess the ListBox has to be unicode, too   :bg


Not one of my brightest ideas :red ...doesn't look so nice ....maybe change to when btn_clicked.....

xandaz

   Well.... JJ... it seems you're in the right and i am in the wrong.

xandaz

   yes from a file seems a good idea.

jj2007

Quote from: xandaz on April 28, 2012, 11:31:11 PM
   yes from a file seems a good idea.

One of my apps can be switched on the fly, in milliseconds, into seven different languages, with almost thousand strings each. I should get the mechanism patented :green