Solved

Inserting Text into a CRichEditCtrl

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
C++ error cannot convert from std::string to const char * 6 246
c++ syntax question 9 52
Embarcadero WebBroker REST server endpoint parameters 2 82
C++ Code Issue 4 25
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 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.

861 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