Solved

Inserting Text into a CRichEditCtrl

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

747 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

18 Experts available now in Live!

Get 1:1 Help Now