June 25, 2024, 10:23:21 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Load file to Richedit

Started by aurelCB, December 05, 2010, 04:17:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Hi all...
Infact this is not question..and if someone know better option
im always ready to learn.
I find that :
SetDlgItemTextA(w1,1,buffer)
not work with richedit control,why im not sure(maby i do something wrong...)
here is my solution:
IF @CONTROLID = richeditID
If @notifycode=0
filename=""
                        buffer=""
filename = FILEREQUEST("Load file",w1,1,filter,"aon")
IF( Openfile(hFile,filename,"R") = 0): ' open a >1MB file
hsize=0
hsize = Len(hFile)
Allocmem htext,hsize,1
hzero=0
Writemem htext,hsize,hzero
Read hFile,htext
'load memory to pointer
pMem=htext
'load stringPointer to Istring
buffer=#<string>pMem
'NOT WORK->SetDlgItemTextA(w1,1,buffer)
Freemem htext
Closefile hFile
ENDIF
'WORK -> show file in richedit
Setcontroltext w1,1,buffer
                ENDIF

LarryMc

Why not use the command that was designed to load a richedit from a string or file?
Quotereturn = CONTROLCMD (window | dialog, ID, @RTLOAD, FILE | STRING, type)

Use this function to load the contents of the rich edit control from an open file or a string variable.

Type is either 0 to load the contents in plain ASCII format or 1 to load the contents in rich text format (*.rtf). Returns number of characters loaded. FILE is a variable of type FILE and must have been successfully opened for reading with the OPENFILE function.


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Simply becose this way i dont wanna use rtload.

King64

Hi Aurel. Assuming to use windows.inc, where _SetDlgItemText stands for SetDlgItemTextA, try with


_SetDlgItemText(w1.hwnd,1,buffer)

because SetDlgItemTextA expects you pass it an handle to the dialog, not the dialog!

aurelCB

Hi King...
Orginaly is espected INT and i understand what you mean ,but this is not main problem then
problem is in variable buffer which must be string(istring) and i have memory so becose of this
i use pointer and work.(but maby im again in wrong...)
However ...it work. ;)

aurelCB

Larry
sorry i dont explain better.
Ok i try with
CONTROLCMD (w1, 1, @RTLOAD,hfile, 0)
but dont load anything probably becose hfile is binary(i guess...)

LarryMc

Aurel

I don't really know what you are doing but it seems to me that EDIT and RICHEDIT controls are for text and not for binary files.  Seems to me all the non printing characters in a binary file would make and EDIT control go crazy.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Larry
Dont worry.
Im just testing how from memory load file into richedit control which
is main operation inside binded ABasic exe.
In another words.
ABasic create exe file which contain abruntime.exe +sourcecode.
Source code is in of course - binary shape.
So when you doubleclick this binded exe, source code is loaded into memory
then from memory is loaded into richedit and executed.
i think that is not to complicated for understand. :)