BBC BASIC for Windows
Programming >> User Interface >> RichEditor
http://bb4w.conforums.com/index.cgi?board=ui&action=display&num=1443773141

RichEditor
Post by KenDown on Oct 2nd, 2015, 08:05am

I find it very useful to use the text editor provided by creating a window with the "EDIT" parameter, but very often I want the program to type stuff in which I then edit or use in some way. I insert characters into the keyboard buffer using the method described by Richard in the Wiki article of the same name.

PROCfx138("Some text"+CHR$13)

inserts the string "Some text" into the keyboard buffer (and that types it into the edit window) followed by a new line.

However I would like to do the same with a "RichEdit" window, but although PROCfx138 will type the required text, I cannot get it to insert a newline. Various cominations of CHR$13 and CHR$10 have been tried, I've even preceded them by CHR$0 in case that was the required. I've tried "|R" or "R". Nothing works.

Any ideas anyone, please?
Re: RichEditor
Post by sveinioslo on Oct 3rd, 2015, 08:25am

In the manual under Library routines/Dialogue boxes/PROC_editbox it says:
Quote:
Setting it to &1004 (ES_WANTRETURN + ES_MULTILINE), along with an appropriate vertical size, creates a multi-line edit box.

Have you tried that ?

Read about it here:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb775464%28v=vs.85%29.aspx

You didn't provide a code snippet to play with, so i haven't tried it. (a bit lazy today)
Svein

Re: RichEditor
Post by KenDown on Nov 19th, 2015, 08:02am

Sorry about the delay. Here's a code snippet that illustrates the problem. What I want is for the same multi-line output in both edit windows.

INSTALL @lib$+"WINLIB5A"
SYS "LoadLibrary","RICHED20.DLL"

edit%=FN_createwindow(@hwnd%,"EDIT","",0,0,600,200,0,&200044,0)
PROCtype("Kendall"+CHR$13)
PROCtype(""+CHR$13)
PROCtype("Down"+CHR$13)
WAIT 400
PROC_closewindow(edit%)
VDU7

edit%=FN_createwindow(@hwnd%,"RichEdit20A","",0,0,600,200,0,&800004,0)
PROCtype("Kendall"+CHR$13)
PROCtype(""+CHR$13)
PROCtype("Down"+CHR$13)
WAIT 400
PROC_closewindow(edit%)

END
:
DEFPROCtype(a$):LOCALi%,c%
SYS"SetForegroundWindow",edit%
FORi%=1TOLENa$:c%=ASCMID$(a$,i%,1):SYS"PostMessage",edit%,258,c%,0:NEXT
ENDPROC

Re: RichEditor
Post by KenDown on Nov 22nd, 2015, 09:04am

Richard has very, very kindly sent me the solution to the problem. I reproduce his solution below.


EM_REPLACESEL = &C2
INSTALL @lib$+"WINLIB5A"
SYS "LoadLibrary","RICHED20.DLL"

edit%=FN_createwindow(@hwnd%,"EDIT","",0,0,600,200,0,&200044,0)
SYS "SendMessage", edit%, EM_REPLACESEL, 0, \
\ "Kendall"+CHR$13+CHR$10+"Down"+CHR$13+CHR$10
WAIT 400
PROC_closewindow(edit%)
VDU7

edit%=FN_createwindow(@hwnd%,"RichEdit20A","",0,0,600,200,0,&800004,0)
SYS "SendMessage", edit%, EM_REPLACESEL, 0, \
\ "Kendall"+CHR$13+CHR$10+"Down"+CHR$13+CHR$10
WAIT 400
PROC_closewindow(edit%)

END

At the risk of sounding ungrateful, although that solves the stated problem, it does not solve the major problem. The reason I want to use RichEdit is so that I can easily deal with foreign language text. My text file might look like this:

COLOUR RED
This is a title
COLOUR BLACK
[Bulgarian cyrillic translation of "This is a title" copied and pasted from Google Translate]

Using the code Richard gave in a previous query for reading from a RichEdit box I now can save a file "something.txt" and the above will reproduce correctly with the Bulgrian cyrillic text appearing in Notepad as Bulgarian cyrillic text.

However when I reload that text file and try to make it appear in the RichEdit box again, I just get gobbledy-gook.
Instead of the cyrillic I get something like "Ето, Госпо". This is the code I am using.

WHILEline$(slide%,line%)<>","ANDline$(slide%,line%)<>"."
SYS"MultiByteToWideChar",0,0,line$(slide%,line%)+CHR$0,-1,U%,3000
SYS"SendMessageW",edit%,194,0,U%
SYS"SendMessage",edit%,194,0,CHR$13+CHR$10
line%+=1
ENDWHILE

I *know* that the call to MultiByteToWideChar is correctly turning the string into something else because it ends up with two bytes for every character, but when it gets transferred into the edit box something goes wrong.

I have tried altering the first two numbers to CP-UTF8 and so on but they either make no difference or make it worse.

If anyone knows how to use that call and can point me in the right direction, I will be most grateful.