[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

Inserting Text into a CRichEditCtrl

Is there an easy way to insert a line of text into a CRichEditCtrl besides SetWindowText which sets the entire doc?  Thanks.
0
jbartlet
Asked:
jbartlet
  • 2
  • 2
1 Solution
 
nietodCommented:
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
 
jbartletAuthor Commented:
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
 
nietodCommented:
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
 
jbartletAuthor Commented:
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now