Solved

Loading file into an Edit/ RichEdit or any text box

Posted on 2001-06-27
14
359 Views
Last Modified: 2007-12-19
0
Comment
Question by:LouisLing
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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 100 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

776 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