PDA

View Full Version : International characters in console windows



Jophur
03-08-2008, 10:47
I have been trying to use local characters in some programs since I stared to use thinBasic some weeks ago. In GUI it works well but I can not find a way to get the correct characters in the Console.

When I run a program in the Console it changes the local character map also causing all printouts to Console to be filled with garbage characters.

Does anyone know how I can use the Console, and still keep my language?

Exemple:

USES "Console"
Console_Writeline ("Printing Swedish alfabet")
Console_Writeline ("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
Console_Writeline ("abcdefghijklmnopqrstuvwxyz")
Console_WaitKey()

ErosOlmi
03-08-2008, 10:57
Hi Jophur,

you can use function

Console_SetOutputCP(<CodePage>)
to set the codepage of the language you need.
I'm sorry we forgot to document this function but it is simple to use. Just locate your code page and call this fucntion.

A sample showing how to use it is: \thinBasic\SampleScripts\Console\Console_ProgressBar4.tBasicc

Let me know if it works.
I will document it in next thinBasic version.

Ciao
Eros

Jophur
03-08-2008, 11:02
Thank you Eros.

I will try this.

Jophur
03-08-2008, 11:37
I put this together to test all my installed Code pages

USES "Console"
For i as DWORD = 0 to 100000
Console_SetOutputCP(i)
if i=Console_GetOutputCP() then
Console_Write("Code page is now set to: " + i + $CRLF)
Console_Write ("ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz" + $CRLF)
endif
next

The only thing that varies are after the end of thinBasic, then the path in the console ends up in different CP's.

ErosOlmi
03-08-2008, 13:14
Jophur,

Code page should be setup only once at the beginning. Codepage code are not random numbers but ISO standards. See (for example) Microsoft reference at http://www.microsoft.com/globaldev/reference/cphome.mspx

So, code 1257 (http://www.microsoft.com/globaldev/reference/sbcs/1257.mspx) should work for you (but I'm not sure which char set you need so I may be wrong):

USES "Console"

'---Print current charset
PrintCharSet

'---Set new charset
Console_SetFileApisToOEM
Console_SetOutputCP(1257)
PrintCharSet

'---Finish
printl
printl "---Press a key to finish---------------------------------------"
waitkey

'---------------------------------
function PrintCharSet() as long
'---------------------------------
local cCount as long

printl "Code page is now set to: " & Console_GetOutputCP()
printl "---Chars-------------------------------------------------------"

for cCount = 33 to 255
print chr$(cCount) & " "
if mod(cCount, 32) = 0 then
printl
end if
next
printl
end function



Which Operating System are you working on? There can be great differences if you are under Win9x or Win2K or above OS.

Thanks
Eros

ErosOlmi
03-08-2008, 15:09
Ok, I found the possible problem why all chars are the same.
TO be able to see different charsets, you need to use trutype fonts for your console output. Changing charset will not work with raster fonts.

So, set "Lucida Console" (for example) in your Console window as default font and than execute again the script mentioned in my previous post. It should work. But again, only fro Operating systems Win2K or above because API to chane charset are not available under Win9x system.

Ciao
Eros

ADDED:
font need is mentioned in Microsoft documenation at http://msdn.microsoft.com/en-us/library/ms686036(VS.85).aspx

Jophur
03-08-2008, 15:19
Hi Eros.

I'm using WinXP SP3, Swedish version.

this is the printout from your script:

Code page is now set to: 850
---Chars-------------------------------------------------------
! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ `
a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ 
ƒ ˆ Š Œ ˇ ˜ š œ ˛ Ÿ
  Ŗ * ŗ Ą
Į Ā Ć Ę Ē Č Ź Ė Ģ Ķ Ī Ļ Ń Ņ Ō Ų Ł Ś Ū Ż ą
į ā ć ę ē č ź ė ģ ķ ī ļ ń ņ ō ų ł ś ū ż ˙
Code page is now set to: 1257
---Chars-------------------------------------------------------
! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ `
a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ 
ƒ ˆ Š Œ ˇ ˜ š œ ˛ Ÿ
  Ŗ * ŗ Ą
Į Ā Ć Ę Ē Č Ź Ė Ģ Ķ Ī Ļ Ń Ņ Ō Ų Ł Ś Ū Ż ą
į ā ć ę ē č ź ė ģ ķ ī ļ ń ņ ō ų ł ś ū ż ˙

---Press a key to finish---------------------------------------

E.g. same for both the 850 & 1257 Code Pages... I can not see any update inside thinbasic, the only change I've seen so far is after thinBasic has completed the script end ended. Then is the Code Page updated inside the console. I will try see what I can get for results if I try to do the same in Open Watcom.

To print the letter "" I need to use chr$(142), this when it really is chr$(196) in both Code Page 850, 1257. I can not see any change in any of the 55 Code pages I have installed on my machine...

Could you try to see what result you get on that script?

ErosOlmi
03-08-2008, 15:23
Jophur,

maybe we were posting at the same time.
Can you see my previous post about changing Console font to a TrueType one and check again.
Attached a screenshot of my example working with a TT font.

Let me know.
Ciao
Eros

Jophur
03-08-2008, 15:34
Thank you Eros,

TrueType was the answer! :D

ErosOlmi
03-08-2008, 15:40
OK, perfect.

I'm checking if there is a programmatic way to change font in Console window but so far I'm not found any. Microsoft documenation seems not having a ...SetFont... function: http://msdn.microsoft.com/en-us/library/ms682073(VS.85).aspx

I will check in some ASM forums. Maybe there is a low level way.

Ciao
Eros

ErosOlmi
03-08-2008, 15:42
I'm moving this thread in Console dedicated forum (http://community.thinbasic.com/index.php?board=71.0).

ErosOlmi
03-08-2008, 16:04
Default Console sets are stored in Windows Registry under the key:
HKEY_CURRENT_USER\Console
Below that key-tree there can be other keys listing application specific setup.

You can write a script to change font name and pitch directly in the registry but I do not think it is good solution.

Anyhow a possible script for changing Registry keys is:


uses "registry"
Registry_SetValue("HKEYCU", "Console\C:_MyApplicationName.exe", "FaceName", "My Font Name")



where:

"Console\C:_MyApplicationName.exe" is the file name of your application.
For thinBasic uses "Console\C:_thinBasic_thinBasic.exe"
and
For thinBasic Console uses "Console\C:_thinBasic_thinBasicC.exe"

"My Font Name" is the name of the font to use. Example "Lucida Console"


Ciao
Eros