Export (0) Print
Expand All
MFC
Expand Minimize

CRichEditCtrl::StreamIn 

Replaces text in this CRichEditCtrl object with text from the specified input stream.


long StreamIn(
   int nFormat,
   EDITSTREAM& es 
);

Parameters

nFormat

Flags specifying the input data formats. See the Remarks section for more information.

es

EDITSTREAM structure specifying the input stream. See the Remarks section for more information.

Number of characters read from the input stream.

The value of nFormat must be one of the following:

  • SF_TEXT   Indicates reading text only.

  • SF_RTF   Indicates reading text and formatting.

Either of these values can be combined with SFF_SELECTION. If SFF_SELECTION is specified, StreamIn replaces the current selection with the contents of the input stream. If it is not specified, StreamIn replaces the entire contents of this CRichEditCtrl object.

In the EDITSTREAM parameter es, you specify a callback function that fills a buffer with text. This callback function is called repeatedly, until the input stream is exhausted.

For more information, see EM_STREAMIN message and EDITSTREAM structure in the Platform SDK.

// My callback procedure that writes the rich edit control contents
// to a file.
static DWORD CALLBACK 
MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
   CFile* pFile = (CFile*) dwCookie;

   *pcb = pFile->Read(pbBuff, cb);

   return 0;
}

// The example code.
   // The pointer to my rich edit control.
   extern CRichEditCtrl* pmyRichEditCtrl;
   // The file from which to load the contents of the rich edit control.
   CFile cFile(TEXT("myfile.rtf"), CFile::modeRead);
   EDITSTREAM es;

   es.dwCookie = (DWORD) &cFile;
   es.pfnCallback = MyStreamInCallback; 
   pmyRichEditCtrl->StreamIn(SF_RTF, es);

Community Additions

ADD
Show:
© 2014 Microsoft