Solved

Loading file into an Edit/ RichEdit or any text box

Posted on 2001-06-27
14
373 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
Industry Leaders: 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 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SetCurrentDirectory path limit 7 144
White board coding practice 3 95
Path to  STL Map header file 1 81
Safe conversion? 4 76
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

733 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