Solved

Inserting Text into a CRichEditCtrl

Posted on 1998-11-02
4
306 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

919 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now