?
Solved

Loading file into an Edit/ RichEdit or any text box

Posted on 2001-06-27
14
Medium Priority
?
386 Views
Last Modified: 2007-12-19
0
Comment
Question by:LouisLing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +5
14 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 6233700
LouisLing,
You're getting the "no text" post because of tabs or special charactors that are inside your question.

Try just posting a few lines.  Don't copy and paste.
0
 

Author Comment

by:LouisLing
ID: 6233718
Sorry... :)

I have a file with funny characters in it... like
(^)$2WJIsdwe923

Then when i load the file with LoadFromFile command into a RichEdit Box, i get only the first line...which is
(
but actually, the file contains
(
dsjkd@34650432kdsxc
s23768765DSF$4

Hope the question is clear...
0
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6233749
You can try with CRichEditCtrl::StreamIn, see its example at the bottom

<MSDN>
CRichEditCtrl::StreamIn
long StreamIn( int nFormat, EDITSTREAM& es );

Return Value

Number of characters read from the input stream.

Parameters

nFormat

Flags specifying the input data formats. See the Remarks section for more information.

es

EDITSTREAM structure specifying the input stream. See the Remarks section for more information.

Remarks

Call this function to replace text in this CRichEditCtrl object with text from the specified input stream.

The value of nFormat must be one of the following:

SF_TEXT   Indicates reading text only.


SF_RTF   Indicates reading text and formatting.
Either of these values can be combined with SFF_SELECTION. If SFF_SELECTION is specified, StreamIn replaces the current selection with the contents of the input stream. If it is not specified, StreamIn replaces the entire contents of this CRichEditCtrl object.

In the EDITSTREAM parameter es, you specify a callback function which fills a buffer with text. This callback function is called repeatedly, until the input stream is exhausted.

For more information, seeEM_STREAMIN message andEDITSTREAM structure in the Win32 documentation.

Example

// My callback procedure that writes the rich edit control contents
// to a file.
static DWORD CALLBACK
MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
   CFile* pFile = (CFile*) dwCookie;

   *pcb = pFile->Read(pbBuff, cb);

   return 0;
}

// The example code.
   // The pointer to my rich edit control.
   extern CRichEditCtrl* pmyRichEditCtrl;
   // The file from which to load the contents of the rich edit control.
   CFile cFile(TEXT("myfile.rtf"), CFile::modeRead);
   EDITSTREAM es;

   es.dwCookie = (DWORD) &cFile;
   es.pfnCallback = MyStreamInCallback;
   pmyRichEditCtrl->StreamIn(SF_RTF, es);
<MSDN>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6233931
I think, RichEdit don't like Control = "^" symbol,
becouse it is begin of some Accelerators: as Contol + c,
Contol + v ...
Try text w/o this symbol.
0
 
LVL 22

Expert Comment

by:ambience
ID: 6234358
LouisKing , i dont remember any LoadFromFile method of CRichEditCtrl , if i am not wrong this is some function that you may have written ?

can post some code ?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6234428
You need to examine the file in binary.  In the VC++ IDE, select Open frm the File menu.  Select Open As Binary (at the bottom) then locate the file and open it.  Now cut and paste the hxidecimal codes from that window into a post here.

Good guess is that the data contains NULLs (hex 00) which has special meaning.

The file might be UNICODE, in which case, you may need to use the SF_UNICODE flag when you create the stream.  

I also don't see anything like LoadFromFile in the Rich Edit documentation.  Can you explain and please show some code?

-- Dan
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6235356
>>I also don't see anything like LoadFromFile in the Rich Edit documentation
LoadFromFile is BCB stuff.
0
 

Author Comment

by:LouisLing
ID: 6236497
Oops... sorry, I'm using Borland C++ builder 4.0 and the command i used is

RichEdit1->Lines->LoadFromFile("test.txt");
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6236809
Do you try w/o "^" ?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6237114
Does test.txt contain any binary NULLs?  Can you load it using notepad.exe or Wordpad.exe?

-- Dan
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 400 total points
ID: 6261998
I hope, now you use text w/o "^" and it works fine. Alex
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6307052
hi LouisLing,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 11

Expert Comment

by:griessh
ID: 7014595
Dear LouisLing

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to split between

     "AlexVirchovsky and DanRollins"

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7030994
Force accepted

** Mindphaser - Community Support Moderator **

DanRollins, there will be a separate question with points for your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question