flat assembler
Message board for the users of flat assembler.

Index > Windows > Loading vars into a menu

Author
Thread Post new topic Reply to topic
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
Simple question ? !

On start the program loads all vars which have to do with the language (e.g. Messageboxes) from languagefiles.

portugues.txt
english.txt
spanish.txt
and so on...

e.g.
section '.data' data readable writeable

msb_msg1 db 30 dup (0),0

The content is loaded from a languagefile

e.g.
This is not possible
Isto nao e possivel
Dies ist nicht moeglich
and so on...

Easy, works well.

But - how to to this with the different menus, which up to now I have to write in the defined language?

e.g.
menu_pt
menuitem '&Tarefas',0,MFR_POPUP
menuitem '&Pula...',m_IDM_T1
menuseparator
menuitem '&Danca...',m_IDM_T2
menuseparator
menuitem '&Chora...',m_IDM_T3,MFR_END

menu_en
menuitem '&Tasks',0,MFR_POPUP
menuitem '&Jump...',m_IDM_T1
menuseparator
menuitem '&Dance...',m_IDM_T2
menuseparator
menuitem '&Cry...',m_IDM_T3,MFR_END

menu_sp
and so on...

I would like to to load these vars as well

e.g.

tasks db 20 dup (0),0
tasks1 db 20 dup (0),0
tasks2 db 20 dup (0),0
tasks3 db 20 dup (0),0

The languagefile loads:

Tasks
Jump...
Dance...
Cry...

or

Tarefas
Pula...
Danca...
Chora...

and so on...

something like ???:

menuitem [tasks],0,MFR_POPUP
menuitem [tasks1],m_IDM_T1
menuseparator
menuitem [tasks2],m_IDM_T2
menuseparator
menuitem [tasks3],m_IDM_T3,MFR_END

I tried everything imaginable. I dont get it.
Same problem with dialogboxes.

I hardly can believe that programs (most today) which offer many different languages, have 25 different menus written in the
section '.rsrc' resource data readable.

Any ideas ?
Post 29 Jan 2014, 14:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17476
Location: In your JS exploiting you and your system
revolution
clamicun wrote:
I hardly can believe that programs (most today) which offer many different languages, have 25 different menus written in the
section '.rsrc' resource data readable.
Multilingual programs usually use a string resource to place all the strings from each language. Then the dialogue resources can point to a string resource by reference and the OS will display the string with the matching language.

Using fixed sized buffers is generally not a good method. All that data copying and having to ensure the buffers are large enough to hold the longest string creates a lot of opportunity for errors.
Post 29 Jan 2014, 14:10
View user's profile Send private message Visit poster's website Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
Multilingual programs usually use a string resource to place all the strings from each language. Then the dialogue resources can point to a string resource by reference and the OS will display the string with the matching language.

Using fixed sized buffers is generally not a good method. All that data copying and having to ensure the buffers are large enough to hold the longest string creates a lot of opportunity for errors.
-------------------

Thank you for the advice, Revolution !
That is more or less what my program does. The mentioned langfiles (e.g. french.txt) consist of one string, which is loaded on startup, depending of an "INIFILE", which contains 'de' or 'en' or 'fr' ..." .

And "ensure the buffers are large enough..". Don't we to always do that ?

But unfortunately you didn't refer to my actual question.
Is it or is it not possible - the way FASM manages menus - to work with variables or must I insert pure text?

menuitem '&Do something',0,MFR_POPUP

Have a nice day!
Clamicun
Post 30 Jan 2014, 14:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17476
Location: In your JS exploiting you and your system
revolution
clamicun wrote:
But unfortunately you didn't refer to my actual question.
Is it or is it not possible - the way FASM manages menus - to work with variables or must I insert pure text?

menuitem '&Do something',0,MFR_POPUP
String resources are just reference numbers that you use instead of a literal string. If the standard macros can't do it you can make yourself a new version of the macros to do what you need. I think such a modification wouldn't be to much.
Code:
menuitem string_resource_identifier_for_do_something,0,MFR_POPUP    
Post 30 Jan 2014, 14:51
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
First of all please use code tags and quote tags.

I'm surprised revolution didn't blow his head on that one


No. There's no need to create 100 menus for 100 languages.

You see, when a program supports multiple languages, it will come with language files (usually DLLs containing string resources).

Each language file/DLL/language pack contains a string table. In this string table, each string has a unique ID number that is the same across all language packs/files/DLLs.

Code:
DEFINE IDS_HELLO = 1

; de.dll
IDS_HELLO "Hello in German"

; ru.dll
IDS_HELLO "Hello in Russia."

; en_Us.dll
IDS_HELLO "Howdy"

; en_GB.dll
IDS_HELLO "H'llo"

; When loading the strings

chosen_lang_pack = "de.dll";

module = LoadLibraryAsResourceNotExecutableForSecurityReasons(chosen_lang_pack);

LoadString(IDS_HELLO,buffer);

AppendMenu(..., ID_HELLO, buffer);
    


If you app supports a really small set of languages, you can just jam-pack them in your EXE. However, adding more language support means updating the EXE also.
Post 30 Jan 2014, 16:41
View user's profile Send private message Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
Thank you both,
Revolution and typedef !

that was it.
Post 30 Jan 2014, 17:30
View user's profile Send private message Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
Unfortunately that was it not.

After a couple of days - trying - I did not succeed.

Espacially I do not know what to do with....

module = LoadLibraryAsResourceNotExecutableForSecurityReasons(chosen_lang_pack);

Wherever I put it, it gives me an errormessage.

Revolutions idea with that MACRO - might be not to much - but I do not understand it at all.

I would be very thankful for some more 'detailed' information, if you please and have the time to do it.

After 3 month of trying 'ASSEMBLER' I start to really like it.
Post 06 Feb 2014, 22:20
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
clamicun,

Naturally LoadLibraryAsResourceNotExecutableForSecurityReasons() isn't exported by Kernel32.DLL. What typedef meant was (probably) LoadLibraryEx(chosen_lang_pack, NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE).
Post 07 Feb 2014, 05:48
View user's profile Send private message Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
invoke LoadLibraryEx,chosen_lang_pack, NULL,LOAD_LIBRARY_AS_IMAGE_RESOURCE
gives an errmsg from fasmw.

But anyway I give it up for a while and use 5 different menus.
Problem with people who know a lot on assembler is, that they mostly are very scarce with explanations
Post 08 Feb 2014, 16:06
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
This isn't an assembly problem.
The problem with people who don't know stuff it that they don't know
Post 08 Feb 2014, 18:43
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
clamicun,

Don't give up, we're here to help but can't do this with that scarce information you've provided.

What kind of errmsg does fasmw gave you? Is that related to undefined LOAD_LIBRARY_AS_IMAGE_RESOURCE symbol? Can't it be resolved using simple 'LOAD_LIBRARY_AS_IMAGE_RESOURCE = 32' definition that stems right from WinBase.h? As an alternative, trivial lucky Google search takes you right to the specification of LoadLibraryEx() with all those flags defined in plain hypertext.

Don't be lazy, do the homework. Wink
Post 09 Feb 2014, 06:23
View user's profile Send private message Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
baldr,
yes thanks - I knew already that LOAD_LIBRARY_AS_IMAGE_RESOURCE = 20h.

I think my information is not scarce at all (first post). All I want, is to write a menu, which can be used with various languages.

And unfortunately I do not succed to get typedefs post from 30 Jan 2014, 14:51 to work with the knowledge I have.

That probably has to do with the fact, that I do not fully understand the "secrets" of string resources.

The syntax of LoadString ??

"A handle to an instance of the module whose executable file contains the string resource" ??

o.k. I do not give up.

P.S.
By the way typedef, semiphilosophical considerations do not help with with assembler.
Post 09 Feb 2014, 15:23
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
There's no philosophy involved here.

The problem is you haven't clearly identified your problem. This is how I see it in this case: Making a menu is not a problem rather your goal. Your problem is the lack of API information that can be easily obtained from MSDN and or visiting revolution's website.

And may I ask: is assembly your first programming language on Windows?

Because if you've made Windows menus in other programming languages, the problem becomes how to use the API in assembly. If however you don't know both then take some time to learn assembly first then learn the API as you go. And you don't just get all the knowledge in one package. It comes after a few trials and errors and some research. Good luck.
Post 09 Feb 2014, 18:26
View user's profile Send private message Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
I knew, you would answer my "by the way". People like you - probably from Northamerica (no insult to Canadians) always do.
I did not mention "philosophy" - I mentioned "semiphilosophy" if know what I mean. And I stick to that.
Good luck as well.
Post 10 Feb 2014, 17:30
View user's profile Send private message Reply with quote
Kenneth



Joined: 16 Nov 2005
Posts: 38
Location: United States of America
Kenneth
I've never attempted to make any of my stuff work in other languages, but I'd imagine I would do something like attached file. Doesn't show it working with menus but the idea is the same. Looks like SetMenuItemInfo would work with menus but not sure, example shows changing texts for button and titlebar.

Basically I would use fasm to compile your own language files like such:
Code:
format binary as 'lng'
use32
org 0
lookuptable     dd string1, string2
string1         du "Ceci n'est pas possible",0
;string1csz = $ - string1
string2         du "Ceci est possible",0
;string1csz = $ - string1                      

Then you can see what languages the user has files for and manually change all your texts using your little custom language file. Set the strings in a static order, the beginning of the language file has offset to correct string to use.

[edit]bug, change line: invoke SendDlgItemMessage, [hWnd], lbLanguages, LB_SETCURSEL, 0, langEnglish
to: invoke SendDlgItemMessage, [hWnd], lbLanguages, LB_SETCURSEL, 0, 0
[/edit]


Description:
Download
Filename: template gui - Copy.zip
Filesize: 4.39 KB
Downloaded: 46 Time(s)

Post 10 Feb 2014, 18:49
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
clamicun wrote:
I knew, you would answer my "by the way". People like you - probably from Northamerica (no insult to Canadians) always do.

Then why are you surprised? Is it wrong to reply? And I don't think only North Americans are the only people who do that.

clamicun wrote:
I did not mention "philosophy" - I mentioned "semiphilosophy" if know what I mean. And I stick to that.
Good luck as well.


I don't know what you mean but in your sentence, semi is modifying the word philosophy thereby making it convey less of what it normally should. So, since semi-philosophy (not much philosophy or little philosophy) still is philosophy, therefore implications dictate you must be talking about philosophy. i.e A semi-circle is still a circle, but not a full circle.
Post 10 Feb 2014, 20:22
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1413
Location: Toronto, Canada
AsmGuru62
Hi clamicun,

So, you are trying to make a program with multi-language interface?
Beside already mentioned methods of doing that (DLLs and whatever...) -- you can also use
simple text files to represent strings you want. Then you simply load these files into memory and get access to text using a simple number.

So, basically, your text file will look like that:
Code:
1. string 1
2. string 2
and so on...
    

so you know which number points to which text.

Then you parse these files and keep a map of strings in memory.
I did stuff like that long ago for Win32 and it was working OK without any DLLs.
Text files must be UNICODE.
Post 10 Feb 2014, 22:04
View user's profile Send private message Send e-mail Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
Thank you all !

Just a bit of explanation.
I am not trying to write a multi-language program, it is ready since 1989 - MS-DOS.
It was some hell to write it - I remember. There were a couple of programes named

name_de.com
name_en.com
name_pt.com
....
You could choose the language by loading another program.

I wrote it with Borland C and in assembler (the asm compiler was something with the name of 'NASM' - I remember that the creator (indian name) was classicly from Bangalore - even 25 years ago).

Now I am retired since last year and have lots of time. So I checked a bunch of old rotten disquetes - (I had to find a very old working computer to read them).

Found the program.
Decided to transform the MS-DOS into Win32 just for fun.
Having done - the last 25 years - computerwork only with php, html, js, css ond so on - I am starting from the bottom.

more...
The old MS-DOS is a program to encrypt files (very popular in these days, that is why I am working on it). The 'algoritmus' is not much 'sophisticated' today, but the NSA is going to hack any program because they very likely invented it.

That's it. Good night

P.S.
I found the name of the asm compiler in the net - It was not Bangalore but Madurai.

NGASM.COM
G.Gurupandian and G.Namasivayam
16, South Veli Street
Madurai - 625 001
Tamil Nadu, India.
Post 11 Feb 2014, 21:59
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
clamicun,

Win32 has embedded facility to serve appropriate string from STRINGTABLE resource depending on current locale. I'll look into that later, probably that'll help.

"Don't sit down, it's time to dig another one. -- For long you live and high you fly -- but only if you ride the tide -- and balanced on the biggest wave -- you race toward an early grave." Wink
Post 11 Feb 2014, 22:51
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.