Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Loading file into an Edit/ RichEdit or any text box

Posted on 2001-06-27
14
Medium Priority
?
391 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

610 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