Solved

Loading file into an Edit/ RichEdit or any text box

Posted on 2001-06-27
14
367 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

828 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