VC 中怎么保存或打开富文本内容?
直接用系统提供的是不行的.我目的就是实现能把带有颜色,字体等信息的文字保存成RTF或DOC型的文件,模仿WORD....
直接用系统提供的是不行的.我目的就是实现能把带有颜色,字体等信息的文字保存成RTF或DOC型的文件,模仿WORD.
展开
1个回答
展开全部
CRichEditCtrl::Stream
CRichEditCtrl::StreamIn
Writes out the contents of this CRichEditCtrl object to the specified output stream.
long StreamOut(
int nFormat,
EDITSTREAM& es
);
Parameters
nFormat
Flags specifying the output data formats. See the Remarks section for more information.
es
EDITSTREAM structure specifying the output stream. See the Remarks section for more information.
Return Value
Number of characters written to the output stream.
Remarks
The value of nFormat must be one of the following:
SF_TEXT Indicates writing text only.
SF_RTF Indicates writing text and formatting.
SF_RTFNOOBJS Indicates writing text and formatting, replacing OLE items with spaces.
SF_TEXTIZED Indicates writing text and formatting, with textual representations of OLE items.
Any of these values can be combined with SFF_SELECTION. If SFF_SELECTION is specified, StreamOut writes out the current selection into the output stream. If it is not specified, StreamOut writes out the entire contents of this CRichEditCtrl object.
In the EDITSTREAM parameter es, you specify a callback function which fills a buffer with text. This callback function is called repeatedly, until the output stream is exhausted.
For more information, see EM_STREAMOUT message and EDITSTREAM structure in the Platform SDK.
Example
// My callback procedure that reads the rich edit control contents
// from a file.
static DWORD CALLBACK
MyStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CFile* pFile = (CFile*) dwCookie;
pFile->Write(pbBuff, cb);
*pcb = cb;
return 0;
}
// The example code.
// The pointer to my rich edit control.
extern CRichEditCtrl* pmyRichEditCtrl;
// The file to store the contents of the rich edit control.
CFile cFile(TEXT("myfile.rtf"), CFile::modeCreate|CFile::modeWrite);
EDITSTREAM es;
es.dwCookie = (DWORD) &cFile;
es.pfnCallback = MyStreamOutCallback;
pmyRichEditCtrl->StreamOut(SF_RTF, es);
CRichEditCtrl::StreamIn
Writes out the contents of this CRichEditCtrl object to the specified output stream.
long StreamOut(
int nFormat,
EDITSTREAM& es
);
Parameters
nFormat
Flags specifying the output data formats. See the Remarks section for more information.
es
EDITSTREAM structure specifying the output stream. See the Remarks section for more information.
Return Value
Number of characters written to the output stream.
Remarks
The value of nFormat must be one of the following:
SF_TEXT Indicates writing text only.
SF_RTF Indicates writing text and formatting.
SF_RTFNOOBJS Indicates writing text and formatting, replacing OLE items with spaces.
SF_TEXTIZED Indicates writing text and formatting, with textual representations of OLE items.
Any of these values can be combined with SFF_SELECTION. If SFF_SELECTION is specified, StreamOut writes out the current selection into the output stream. If it is not specified, StreamOut writes out the entire contents of this CRichEditCtrl object.
In the EDITSTREAM parameter es, you specify a callback function which fills a buffer with text. This callback function is called repeatedly, until the output stream is exhausted.
For more information, see EM_STREAMOUT message and EDITSTREAM structure in the Platform SDK.
Example
// My callback procedure that reads the rich edit control contents
// from a file.
static DWORD CALLBACK
MyStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CFile* pFile = (CFile*) dwCookie;
pFile->Write(pbBuff, cb);
*pcb = cb;
return 0;
}
// The example code.
// The pointer to my rich edit control.
extern CRichEditCtrl* pmyRichEditCtrl;
// The file to store the contents of the rich edit control.
CFile cFile(TEXT("myfile.rtf"), CFile::modeCreate|CFile::modeWrite);
EDITSTREAM es;
es.dwCookie = (DWORD) &cFile;
es.pfnCallback = MyStreamOutCallback;
pmyRichEditCtrl->StreamOut(SF_RTF, es);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询