chcw
asked on
Why CRichEditCtrl cannot show images in a RTF file?
I create a dialogbox and add a CRichEditCtrl on it. Then I use the following codes to read a RTF file into the CRichEditCtrl, as follows(this is the sample from MSDN):
// 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);
However, when the codes are executed, only the texts in RTF can be displayed in CRichEditCtrl, the images cannot be displayed. Why?
// 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(
However, when the codes are executed, only the texts in RTF can be displayed in CRichEditCtrl, the images cannot be displayed. Why?
Check out this link http://www.codeguru.com/Cpp/controls/richedit/article.php/c5383
Try this class also http://www.codeproject.com/richedit/autoricheditctrl.asp
ASKER
Thanks to roshmon, but what you mentioned is just insert an image into the RichEdit control. If using this example in my case, I must do as follows:
1. parse the RTF tags in MyStreamInCallback function
2. retrieve the image data from the RTF tags
3. convert it into a binary data
4. determine the insert point for the image, and thinking of possible text around the image.
5. then use the sample you provided to insert the image into RTF.
This procedure is very inconvenient. At least I need to spend time to study the RTF format. Are there any better solution to this problem?
1. parse the RTF tags in MyStreamInCallback function
2. retrieve the image data from the RTF tags
3. convert it into a binary data
4. determine the insert point for the image, and thinking of possible text around the image.
5. then use the sample you provided to insert the image into RTF.
This procedure is very inconvenient. At least I need to spend time to study the RTF format. Are there any better solution to this problem?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.