The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: hfheatherfox07 on April 24, 2012, 10:02:37 PM

Title: When to use STRINGTABLE?
Post by: hfheatherfox07 on April 24, 2012, 10:02:37 PM
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
Title: Re: When to use STRINGTABLE?
Post by: dedndave on April 24, 2012, 11:28:44 PM
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
Title: Re: When to use STRINGTABLE?
Post by: NoCforMe on April 24, 2012, 11:55:20 PM
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.
Title: Re: When to use STRINGTABLE?
Post by: dedndave on April 25, 2012, 12:04:14 AM
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
Title: Re: When to use STRINGTABLE?
Post by: jj2007 on April 25, 2012, 01:54:46 AM
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
Title: Re: When to use STRINGTABLE?
Post by: hfheatherfox07 on April 25, 2012, 02:38:47 AM
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
Title: Re: When to use STRINGTABLE?
Post by: 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
Title: Re: When to use STRINGTABLE?
Post by: 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.
Title: Re: When to use STRINGTABLE?
Post by: jj2007 on April 25, 2012, 10:20:34 PM
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.
Title: Re: When to use STRINGTABLE?
Post by: dedndave on April 25, 2012, 10:27:48 PM
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
Title: Re: When to use STRINGTABLE?
Post by: hfheatherfox07 on April 27, 2012, 08:27:47 PM
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.....
Title: Re: When to use STRINGTABLE?
Post by: xandaz on April 28, 2012, 11:25:26 PM
   Well.... JJ... it seems you're in the right and i am in the wrong.
Title: Re: When to use STRINGTABLE?
Post by: xandaz on April 28, 2012, 11:31:11 PM
   yes from a file seems a good idea.
Title: Re: When to use STRINGTABLE?
Post by: jj2007 on April 29, 2012, 12:49:35 AM
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