Solved

Inserting Text into a CRichEditCtrl

Posted on 1998-11-02
4
310 Views
Last Modified: 2008-02-01
Is there an easy way to insert a line of text into a CRichEditCtrl besides SetWindowText which sets the entire doc?  Thanks.
0
Comment
Question by:jbartlet
[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
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1176840
You can use the StreamIn() member to insert text into the control (replacing the current selection, so make sure there is no selection).

Let me know if you have questions.
0
 

Author Comment

by:jbartlet
ID: 1176841
I find this function a little confusing for just inserting text (having to provide a function pointer etc).  Could you provide me with a simple example?  Thanks.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1176842
You just declare a function like

DWORD CALLBACK(DWORD Cookie,LPBYTE *DstPtr,LONG ReqLen,LONG *ActLenPtr)
{
}

The function copies data to the memory specified by DstPtr.  The maximum length of the data to be copied is specified to the function in ReqLen.  You can copy less data than this rquested length, if you are at the end of the data to be copied.  You update the LONG that ActLenPtr points to indicate the length you actually copied.  Cookie is used to pass additional parameters to your function, for andy purposes that you need.  (It might be used to pass a file handle, if the reading was occuring from a file, for example.)

The following example could be used to read data from a buffer in memory.  The BufInf structure specified information about the buffer and is passed to the callback function using the cookie value.  for example.

struct BufInf
{
   char *DatPtr; // -> data to be written.
   int     LenWrt;  // Length written.  Constructor could set to 0.
   int    TotLen; // Total length.
}


DWORD CALLBACK(DWORD Cookie,LPBYTE *DstPtr,LONG ReqLen,LONG *ActLenPtr)
{
   BufInf  *InfPtr = (BufInf *) Cookie;  // Cast back to buffer information structure.

   int CpyLen = ReqLen;  // Length to copy.
   int LenRem = InfPtr->TotLen - InfPtr->LenWrt; // Length left to copy.

  if (CpyLen > LenRem) // If we are at the end, then
    CpyLen = LenRem;  // Just use the length remaining.

   memcpy(DstPtr,InfPtr->DatPtr+InfPtr->LenWrt,CpyLen);  // copy data.

   IntPtr->LenWrt += CpyLen; // Update the length written.
   *ActLenPtr = CpyLen;  // Report back how much was actually written.

   return 0;
}
0
 

Author Comment

by:jbartlet
ID: 1176843
Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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.

691 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