December 11, 2024, 09:52:56 PM

News:

IWBasic runs in Windows 11!


Unicode in a RichEdit Control, continued

Started by okchoir, March 17, 2017, 12:07:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

okchoir

I have been working, off and on, on Bible analysis programs.  This time I want to add a display of Hebrew characters in a richedit control, and finally succeeded.  I'm sharing a code demo of this, and a screen capture of the control (see attachment) with one Hebrew word, the first word in the book of Genesis.  I am by no measure an expert with this language - only a beginner.  Hope this is useful to someone.  -Jack Harris

'Hebrew
   '16MAR17


$DEFINE UNICODE
AUTODEFINE "OFF"
$include "windowssdk.inc"

TYPE _settextex
WORD flags :'ST_UNICODE = 0x0008 (8), from riched.h
UINT codepage :'=CP_UTF8 :' = 0xFDE9 (65001)
ENDTYPE

TYPE UnicodeString
  UNION
IWSTRING UnicodeStr$[500]
CHAR UniByteStr[1000]
  ENDUNION
ENDTYPE

DEF win:WINDOW
DEF run,key:INT

DEF wParamOUT:_settextex
DEF lParam:UnicodeString

DEF hRichEdit:UINT
DEF hLibModule:INT
$DEFINE ST_UNICODE 0x0008
hLibModule = LoadLibraryW(L"Riched20.dll" )

CONST EM_SETTEXTEX = 1121 :'(WM_USER + 97)
wParamOUT.flags = ST_UNICODE :'ST_UNICODE
wParamOUT.codepage = CP_UTF8 :' = 0xFDE9 (65001)

OPENWINDOW win,200,200,820,280,@SIZE,0,"HEBREW",&mainwindow

'Add the Rich Edit Control.
hRichEdit = CONTROLEX win, "RichEdit20W", "", 10, 115, 500, 60, @CTEDITMULTI, @EXCLIENTEDGE, 1
SETCONTROLCOLOR win,1,0,RGB(255,155,155)
SETFONT win,"Ezra SIL",12,400,0,1 'Hebrew font 'This Control is ID=1

run = 1
/*
Table of Hebrew Alphabet with UTF-8 codes.

UTF-8 Name
   D7 90 ALEF
   D7 91 BET
   D7 92 GIMEL
   D7 93 DALET
   D7 94 HE
   D7 95 VAV
   D7 96 ZAYIN
   D7 97 HET
   D7 98 TET
   D7 99 YOD
   D7 9A KAF,FINAL
   D7 9B KAF
   D7 9C LAMED
   D7 9D MEM,FINAL
   D7 9E MEM
   D7 9F NUN,FINAL
   D7 A0 NUN
   D7 A1 SAMEKH
   D7 A2 AYIN
   D7 A3 PE,FINAL
   D7 A4 PE
   D7 A5 TSADI,FINAL
   D7 A6 TSADI
   D7 A7 QOF
   D7 A8  RESH
   D7 A9 SHIN
   D7 AA TAV
*/

' Hebrew Letters are displayed right to left, so the first letter code in lParam is the right-hand end.
'lParam is loaded with six letters, the first word in Genesis 1:1.
' HEX      DECIMAL  HEBREW LETTER NAME
lParam.UniByteStr[0] = 0xD7     '(215) BET
lParam.UniByteStr[1] = 0x91     '(145) (2nd Unicode Byte)
lParam.UniByteStr[2] = 0xD7     '(215) RESH
lParam.UniByteStr[3] = 0xA8     '(168) (2nd Unicode Byte)
lParam.UniByteStr[4] = 0xD7     '(215) ALEF
lParam.UniByteStr[5] = 0x90     '(144) (2nd Unicode Byte)
lParam.UniByteStr[6] = 0xD7     '(215) SHIN
lParam.UniByteStr[7] = 0xA9     '(169) (2nd Unicode Byte)
lParam.UniByteStr[8] = 0xD7     '(215) YOD
lParam.UniByteStr[9] = 0x99     '(153) (2nd Unicode Byte)
lParam.UniByteStr[10] = 0xD7    '(215) TAV
lParam.UniByteStr[11] = 0xAA    '(170) (2nd Unicode Byte)

SendMessageW(hRichEdit,EM_SETTEXTEX,&wParamOUT,&lParam)
WAIT 1 :'Allow Window to update


WAITUNTIL run = 0
CLOSEWINDOW win

END

'  ****** Subroutine ******************************************

SUB mainwindow(),INT
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
run=0
CASE @IDCHAR
key = @CODE
IF key = 27 THEN run = 0
ENDSELECT
RETURN 0
ENDSUB

'

Brian

Clever stuff - I like it...

In looking up the first few words of Genesis (I am not a religious person, by any means, but always happy
to learn new stuff), I came across this website, which was interesting:

http://www.rebjeff.com/blog/bereshit-in-the-beginning-of-what

Brian