Hello Charles..
How I can Display Chinese Letters in oxygen? In Oxide there are only to See ??? Three or more Questionmarks
In my simple Texteditor it Shows correct Chinese Symbols
uses corewin
extern lib "User32.dll"
! CharUpper "CharUpperW" '1
! CharLower "CharLowerW" '1
! MessageBox "MessageBoxW" '1
end extern
wstring tab=wchr(9)
wstring sep
dim strx as string =" 你好吗 " '' chinese letters
mbox mid(**strx,2)
' unicode problem
" 你好吗 "
' translation: chinesisch: Nǐ hǎo ma
' english: hello how are you?
' german: "hallo wie gehts?"
Made this example Charles
But the Chinese Text isnt displayed correct
wstring hellochinese
sub getwstrings()
'very simple
int n=0
int p1=1, p2, le
wstring wcrlf=wchr(13)+wchr(10)
wstring txt=wstring getfile "chines.txt"
if len(txt)=0 then mbox "Cannot load chines.txt"
while 1
p2=instr(p1,txt, wcrlf)
if p2=0 then exit while
le=p2-p1+1
n+=1
hellochinese=mid(txt,p1,le)
p1=p2+2
print hellochinese
wend
end sub
getwstrings()
Chinese.txt ' Hope this can displayed Here correct
你好吗 these are chinese letters
Try splitting this dim line:
wstring txt=wstring getfile "chines.txt"
wstring txt
txt=(wstring) getfile "chines.txt"
'or
' txt= cast wstring getfile "chines.txt"
Sorry No Chance same result Like before No Chinese Symbols are displayed
uses corewin
'' Try splitting this dim line:
'' wstring txt=wstring getfile "chines.txt"
'' wstring txt
'' txt=wstring getfile "chines.txt"
'or
' txt= cast wstring getfile "chines.txt"
''print txt
wstring hellochinese
sub getwstrings()
'very simple
int n=0
int p1=1, p2, le
wstring wcrlf=wchr(13)+wchr(10)
wstring txt
txt=wstring getfile "chines.txt"
if len(txt)=0 then mbox "Cannot load chines.txt"
while 1
p2=instr(p1,txt, wcrlf)
if p2=0 then exit while
le=p2-p1+1
n+=1
hellochinese=mid(txt,p1,le)
p1=p2+2
print hellochinese
wend
end sub
getwstrings()
ok, start with something really simple:
putfile "t.txt","AA" 'cheating!
wstring ws
ws=cast wstring getfile("t.txt")
print ws
Hi Charles,
I noticed a small bug in \demos\Unicode\REdit_Unicode\RicheditUnicode.o2bas. There is an error message:
Error: cannot use variable as constant
Word: fname
Proc: wndproc
Col: 1
Line: 274
File: 'man source'
The app worked with an older version of O2, although it is not quite correct. After I modified line 273 / 274 to:
wstring text3
text3 = (wstring) wgetfile (fName)
everything worked as expected.
I attach the three images of the used test files.
Yes Roland, I noticed a few breakages in the Unicode folder, but unfortunately I have very limited time to spare for the next few weeks. Perhaps you could isolate the problems syntactically.. It's probably something tiny.
At Roland there are only few Changes to make fixed Code below
'https://docs.microsoft.com/de-de/windows/desktop/Controls/rich-edit-controls
$ filename "RicheditUnicode.exe"
'uses RTL32
'uses RTL64
uses WinData
% COLOR_WINDOW = 5
% ES_SAVESEL=0x8000
% SWP_NOZORDER=4
% SS_LEFT=0
% SS_NOTIFY=0x0100
% SF_TEXT=1
% EM_SETTEXTEX=1121
% ST_UNICODE=8
% CP_ACP=0
% CP_UTF8=65001 'codepage UTF8
% WM_CLEAR=771
type SETTEXTEX
dword flags
uint codepage
end type
extern lib "Kernel32.dll"
! GetCommandLine "GetCommandLineW" '0
! GetModuleHandle "GetModuleHandleW" '1
end extern
extern lib "User32.dll"
! CreateWindowEx "CreateWindowExW" '12
! DefWindowProc "DefWindowProcW" '4
! DispatchMessage "DispatchMessageW" '1
! GetClientRect '2
! GetMessage "GetMessageW" '4
! GetSystemMetrics '1
! IsWindowUnicode
! LoadIcon "LoadIconW" '2
! LoadCursor "LoadCursorW" '2
! MessageBox "MessageBoxW" '1
! PostQuitMessage '1
! RegisterClass "RegisterClassW" '1
! SendMessage "SendMessageW" '4
! SetFocus
! SetWindowPos '7
! SetWindowText "SetWindowTextW" '2
! ShowWindow '2
! TranslateMessage '1
! UpdateWindow '1
end extern
extern lib "Comctl32.dll"
! InitCommonControlsEx '1
end extern
#ifndef mode64bit
extern lib "Msvcrt.dll" cdecl
#else
extern lib "Msvcrt.dll"
#endif
! _wfopen
! fclose
! fread
! fseek
! ftell
end extern
function wGetFile(wstring name) as wstring
==========================================
sys f
int e
wstring m="rb"
wbstring s
f=_wfopen name,m 'open for reading binary
if f=0 then return ""
fseek f,0,2 'end of file
e=ftell f 'get position
fseek f,0,0 'beginning of file
strptr s=getmemory e 'create buffer to fit
fread s,1,e,f 'load buffer
fclose f 'close file
return s
end function
function wGetFile(wstring name) as string
==========================================
sys f
int e
wstring m="rb"
bstring s
f=_wfopen name,m 'open for reading binary
if f=0 then return ""
fseek f,0,2 'end of file
e=ftell f 'get position
fseek f,0,0 'beginning of file
strptr s=getmemory e 'create buffer to fit
fread s,1,e,f 'load buffer
fclose f 'close file
return s
end function
'create a structure of INITCOMMONCONTROLSEX
INITCOMMONCONTROLSEXt iccex
iccex.dwSize=sizeof(iccex)
'Register Common Controls
iccex.dwICC= 0xffff
InitCommonControlsEx(@iccex)
LoadLibrary("RICHED20.DLL")
declare function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
'=========
'MAIN CODE
'=========
dim cmdline as wchar ptr, hInstance as sys
@cmdline=GetCommandLine
hInstance=GetModuleHandle 0
sys hButton1, hButton2, hREdit, hEdit, Group
% ID_BUTTON1=1000
% ID_BUTTON2=1001
sys lbl[5]
wstring lblTxt[5]={" Ansi","UTF-16","UTF-8","Text","Open file as: "}
sys radio[5]
sys id_radio[5]={101,102,103,104}
'WINDOWS START
'=============
WinMain hInstance,0,cmdline,SW_NORMAL
end
function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
WndClass wc
MSG wm
sys hwnd, Wwd, Wht, Wtx, Wty, Tax
wstring classname="REDemo"
wc.style = CS_HREDRAW or CS_VREDRAW
wc.lpfnWndProc = @WndProc
wc.cbClsExtra =0
wc.cbWndExtra =0
wc.hInstance =inst
wc.hIcon=LoadIcon 0, IDI_APPLICATION
wc.hCursor=LoadCursor 0,IDC_ARROW
wc.hbrBackground = COLOR_WINDOW
wc.lpszMenuName =null
wc.lpszClassName = strptr classname
RegisterClass (@wc)
Wwd = 640 : Wht = 400
Tax = GetSystemMetrics SM_CXSCREEN
Wtx = (Tax - Wwd) /2
Tax = GetSystemMetrics SM_CYSCREEN
Wty = (Tax - Wht) /2
'Main Window
hwnd = CreateWindowEx 0,wc.lpszClassName, wstring("OXYGEN BASIC"),WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
'Buttons
hButton1=CreateWindowEx(0,
wstring("Button"), wstring("Open File"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
500, 10, 80 ,25,
hwnd,ID_BUTTON1,inst, 0)
hButton2=CreateWindowEx(0,
wstring("Button"), wstring("Clear REdit"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
500, 45, 80 ,25,
hwnd,ID_BUTTON2,inst, 0)
'Edit
hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,
wstring("Edit"), wstring(""),
WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | ES_AUTOHSCROLL,
20, 10, 450 ,25,
hwnd,0,inst,0)
'Labels
int x, lft, wid
lft=130 : wid=50
for x=1 to 5
if x=5 then lft=-340 : wid=90
lbl[x]=CreateWindowEx(0,
wstring("Static"), wstring(""),
WS_CHILD | WS_VISIBLE | SS_LEFT,
lft+((x-1)*90), 45, wid ,25,
hwnd,0,inst,0)
SetWindowText(lbl[x],lblTxt[x])
next x
'Radios
for x=1 to 4
radio[x]=CreateWindowEx(0,
wstring("Button"), wstring(""),
WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
180+((x-1)*90), 45, 15 ,15,
hwnd,id_radio[x],inst,0)
next x
SendMessage(radio[1], BM_SETCHECK, true,0)
'Richedit
hREdit=CreateWindowEx(WS_EX_CLIENTEDGE,
wstring("RichEdit20W"), wstring(""),
WS_CHILDWINDOW|WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_AUTOVSCROLL | ES_SAVESEL | ES_MULTILINE | WS_BORDER | ES_WANTRETURN,
20, 60,200,25,
hwnd,0,inst,0)
SetFocus(hEdit)
ShowWindow hwnd,SW_SHOW
UpdateWindow hwnd
sys bRet
do while bRet := GetMessage (@wm, 0, 0, 0)
if bRet = -1 then
'show an error message
else
TranslateMessage @wm
DispatchMessage @wm
end if
wend
end function
function WndProc (sys hWnd, uint wMsg, sys wParam, lparam ) as sys callback
SETTEXTEX settext
select wMsg
case WM_COMMAND
select loword(wParam)
case ID_BUTTON1
wstring fName = space 256
SendMessage(hEdit, WM_GETTEXT, len(fName), fName)
fname=ltrim(rtrim(fname))
if len(fname)>0 then
if SendMessage(Radio[1],BM_GETCHECK,0,0)=BST_CHECKED then 'Ansi
string text1
text1 = wgetfile (fName)
if len(text1)=0 then
MessageBox(hWnd, wstring(fName) + " missing or load failure!", wstring("Load File"), MB_OK or MB_ICONASTERISK)
else
'RegisterClassW creates Unicode window, so translate to Unicode
settext.flags=ST_UNICODE
settext.codepage=CP_ACP 'System codepage
SendMessage(hREdit, EM_SETTEXTEX, &settext, text1)
end if
end if
if SendMessage(Radio[2],BM_GETCHECK,0,0)=BST_CHECKED then 'Unicode
wstring text2
text2 = (wstring) wgetfile (fName)
if len(text2)=0 then
MessageBox(hWnd, wstring(fName) + " load failure!", wstring("Load File"), MB_OK or MB_ICONASTERISK)
else
SendMessage(hREdit, WM_SETTEXT, 0, text2)
end if
end if
if SendMessage(Radio[3],BM_GETCHECK,0,0)=BST_CHECKED then 'UTF8
string text3
wstring text3 = wstring wgetfile (fName)
if len(text3)=0 then
MessageBox(hWnd, wstring(fName) + " missing or load failure!", wstring("Load File"), MB_OK or MB_ICONASTERISK)
else
'RegisterClassW creates Unicode window, so translate to Unicode
settext.flags=ST_UNICODE
settext.codepage=CP_UTF8 'cp 65001
SendMessage(hREdit, EM_SETTEXTEX, &settext, text3)
end if
end if
if SendMessage(Radio[4],BM_GETCHECK,0,0)=BST_CHECKED then 'Plain Text
string text4
text4 = wgetfile (fName)
if len(text4)=0 then
MessageBox(hWnd, wstring(fName) + " missing or load failure!", wstring("Load File"), MB_OK or MB_ICONASTERISK)
else
'Workaround
text4=chr(32) & text4
SendMessage(hREdit, WM_SETTEXT, SF_TEXT, text4)
end if
end if
end if
case ID_BUTTON2
SendMessage(hREdit, EM_SETSEL, 0, -1)
SendMessage(hREdit, WM_CLEAR, 0, 0)
end select
case WM_SIZE
RECT rcClient
// Calculate remaining height and size edit
GetClientRect(hwnd, &rcClient)
SetWindowPos(hREdit, NULL, 0, rcClient.top+75, rcClient.right, rcClient.bottom-75, SWP_NOZORDER)
case WM_DESTROY
PostQuitMessage 0
case WM_KEYDOWN
Select wParam
Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0 'ESCAPE
End Select
case else
function=DefWindowProc hWnd,wMsg,wParam,lParam
end select
end function ' WndProc
@charles
All OK tested putfile and to load a songtext too
Ws=wstring getfile("t.txt) ' AA
(You must deleted in your Code Cast)
1)
'ok, start with something really simple:
uses corewin
' all ok here
'
putfile "t.txt","AA" 'cheating!
wstring ws
'ws=cast wstring getfile("t.txt")
ws=wstring getfile("t.txt") ' AA
print ws
putfile "t1.txt","BB" 'cheating!
wstring ws2
ws2=wstring getfile("t1.txt") ' BB
print ws2
putfile "t2.txt","turnturnturn" 'cheating!
wstring ws3
ws3=wstring getfile("t2.txt") ' turnturnturn
print ws3
' GETFILE only ok if you are changing wstring to string
'
' songtext turnturnturn, the byrds
' all ok if you are using instead of wstring-> string
string mytxt : getfile "turnturnturn.txt",mytxt
print mytxt
2)
If you are using wstring mytext2 : getfile "turnturnturn.txt",mytext2 : Print mytext2 I have Got Strange Symbols
'ok, start with something really simple:
uses corewin
' all ok here
'
putfile "t.txt","AA" 'cheating!
wstring ws
'ws=cast wstring getfile("t.txt")
ws=wstring getfile("t.txt") ' AA
print ws
putfile "t1.txt","BB" 'cheating!
wstring ws2
ws2=wstring getfile("t1.txt") ' BB
print ws2
putfile "t2.txt","turnturnturn" 'cheating!
wstring ws3
ws3=wstring getfile("t2.txt") ' turnturnturn
print ws3
' GETFILE only ok if you are changing wstring to string
'
' songtext turnturnturn, the byrds
' all ok if you are using instead of wstring-> string
string mytxt : getfile "turnturnturn.txt",mytxt
print mytxt
' next line not ok I have got strange symbols
'
wstring mytxt2 : getfile "turnturnturn.txt",mytxt2
print mytxt2
PS add Songtext "turnturnturn.txt"
Hi Frank,
the demos in the Unicode folder were written before Charles created CoreWinW.inc and WindataW.inc. It would be interesting to apply these include files to the demos. Personally, however, I believe that it is neccessary to use a Unicode keyboard to develop and test more elaborated code and that someone should speak a language like Greek, Russian etc. In this respect, I miss Mike Lobanovsky very much.
Here's another attempt and does work much better :) although I have No Idea how to get all Chinese Unicode Points for an alphabeth it doesn't exist there Like in english french greek
' chinese unicode try 1, oxygen basic, by frank bruebach, 04-06-2024
'
$ filename "Alphabets.exe"
'use rtl32
'use rtl64
uses corewin
extern lib "User32.dll"
! CharUpper "CharUpperW" '1
! CharLower "CharLowerW" '1
! MessageBox "MessageBoxW" '1
end extern
wstring tab=wchr(9)
wstring sep
function setup_alphabet(int length_U, wstring lang_U, lang_L) as wstring
int n=0, x
int le=length_U
wstring lang
wstring capital=space 1, small=space 1
wstring capital2=space 1, small2=space 1
for x=1 to le
n+=1
sep=") " : if n<10 then sep=") "
' lang &= n & sep & mid(lang_U,n,1) & tab & mid(lang_L,n,1) & tab
'Testing CharUpper and CharLower, ucase and lcase functions
capital=mid(lang_L,n,1) : CharUpper(capital)
small=mid(lang_U,n,1) : CharLower(small)
capital2=mid(lang_L,n,1) : capital2=ucase(capital2)
small2=mid(lang_U,n,1) : small2=lcase(small2)
lang &= n & sep & mid(lang_U,n,1) & capital & capital2 & tab & mid(lang_L,n,1) & small & small2 & tab
next
return lang
end function
'------------------------------- NEW ATTEMPT ----------------------------- //
' unicode code points
wstring Chinese_U=wchr(20044)+wchr(21439)
wstring Chinese_L=wchr(20045)+wchr(21440)
wstring Chinese=setup_alphabet(len(Chinese_U), Chinese_U, Chinese_L)
MessageBox 0, Chinese ,wstring("Chinese Alphabet"),0
'------------------------------- NEW ATTEMPT ----------------------------- //
wstring Grecian_U=
wchr(913)+wchr(914)+wchr(915)+wchr(916)+wchr(917)+wchr(918)+wchr(919)+wchr(920)+wchr(921)+wchr(922)+
wchr(923)+wchr(924)+wchr(925)+wchr(926)+wchr(927)+wchr(928)+wchr(929)+wchr(931)+wchr(932)+wchr(933)+
wchr(934)+wchr(935)+wchr(936)+wchr(937)+wchr(938)+wchr(939)
wstring Grecian_L=
wchr(945)+wchr(946)+wchr(947)+wchr(948)+wchr(949)+wchr(950)+wchr(951)+wchr(952)+wchr(953)+wchr(954)+
wchr(955)+wchr(956)+wchr(957)+wchr(958)+wchr(959)+wchr(960)+wchr(961)+wchr(963)+wchr(964)+wchr(965)+
wchr(966)+wchr(967)+wchr(968)+wchr(969)+wchr(970)+wchr(971)
wstring Grecian=setup_alphabet(len(Grecian_U), Grecian_U, Grecian_L)
MessageBox 0, Grecian ,wstring("Grecian Alphabet"),0
==============================================================
'This is for testing the own keyboard
wstring MyAlphabet_U="ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜß"
wstring MyAlphabet_L="abcdefghijklmnopqrstuvwxyzäöüß"
wstring MyAlphabet=setup_alphabet(len(MyAlphabet_U), MyAlphabet_U, MyAlphabet_L)
MessageBox 0, MyAlphabet ,wstring("My Alphabet - Testing the own keyboard"),0