Originally posted by: hxbings
This demo project is very good.And now i have a problem ussing the RichEdit Control in a dialogbox,how can i insert any registered object into the RichEdit Control placed on a dialog?even more,can i use this control as the CRichEditView?
Thanks a lot!
Originally posted by: Adrian Pirvu
Please watch memory allocation while inserting several bitmaps - it grows with 1M for each 30-50 bitmaps added.
Is it a fix for this?
Thank you
Originally posted by: V.Srinivas Chakravarty
Hi All,
The code provided by Hani Atassi is not working if we keep Inserting the bitmap miltiple number of times.I first insert the text into rich edit control using the ReplaceSel(..) method and then the bitmap, repeate this step several times ,then the problem occurs i.e;the bitmap doesn'getInserted .I am using the win32 functions LoadImage and CopyImage to get the handle of the bitmap to pass to the InsertBitmap function.
Is this the problem with the code provided in this article or with the CRichEditCtrl.
If anyone has any remedy for it ,please reply that to my mail-id.
regards,
Srinivas Chakravarty
Originally posted by: Ravi Iyer
I found this to be most useful, and also to the point.
I have another requirement though to allow customization of background color along with custom images.
However I notice if I change the background color the mask on the previously inserted images fail. And you can see the solid rectangle behind the image.
Is there a solution to make multiple calls to SetBackgroundColor and still preserve the transparency of existing images on the rich Edit ?
Thanks again.
Ravi
Originally posted by: Jorge
Dear All,
I have modified CImageDataObject to allow the insertion of CF_ENHMETAFILE instead of CF_BITMAP. The inserted object is placed and visualized correctly in the CRichEditCtrl.
However, there is a problem when I save the CRichEditCtrl
contents to a file. It seems the rtf is saved correctly but, when I open the saved file with Word or WordPad, the metafile object appears in blank. That is, there is a box with the right size but empty.
I checked the rtf file and the code for the metafile is inside but I guess it is not the right code.
The context in which I'm using the CImageDataObject is in a dialog box containing a CRichEditCtrl as a control.
I am using the following code to save the rich edit control.
DWORD CALLBACK CRepDlg::RichStreamOut(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CString *psEntry = (CString*) dwCookie;
CString tmpEntry = "";
tmpEntry = (CString) pbBuff;
*psEntry += tmpEntry.Left(cb);
return 0;
}
void CRepDlg::OnButton2()
{
EDITSTREAM es;
es.dwError = 0;
es.pfnCallback = RichStreamOut;
CString sRTF = ""; //
es.dwCookie = (DWORD) &sRTF
CRichEditCtrl* pRich = (CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1);
pRich->StreamOut(SF_RTF, es);
CString sFileName = "File.rtf";
CFile f(sFileName, CFile::modeCreate | CFile::modeWrite);
CArchive a(&f, CArchive::store);
a.WriteString(sRTF);
a.Close();
f.Close();
}
So, please, I need to know what is going wrong here. Should I do something more to save properly the inserted object?.
Jorge
ReplyOriginally posted by: Weiye
Is is possible to have this functionality applied to CEdit control instead?
ReplyOriginally posted by: Stephane Lesage
// Set-up the OLE Callback
IRichEditOleCallback* mREOLECallback = new REOLECallback;
// Class definition
class REOLECallback : IRichEditOleCallback
// Methods of the IUnknown interface
// Methods of the IRichEditOleCallback interface
// Data
// Class implementation
STDMETHODIMP REOLECallback::GetNewStorage(LPSTORAGE FAR *lplpstg)
If you want object insertion operations to work in your RichEdit Control,
you have to supply an IRichEditOleCallback interface
and implement the GetNewStorage method.
::SendMessage(mHWnd, EM_SETOLECALLBACK, 0, (LPARAM) mREOLECallback);
{
public:
// Constructor / Destructor
REOLECallback () { mRefCounter = 0; }
~REOLECallback () {}
STDMETHOD_(ULONG, AddRef) (void) { mRefCounter++; return mRefCounter; }
STDMETHOD_(ULONG, Release) (void) { if ( --mRefCounter == 0 ) delete this; return mRefCounter; }
STDMETHOD(QueryInterface) (REFIID iid, void** ppvObject)
{
if (iid == IID_IUnknown || iid == IID_IRichEditOleCallback) { *ppvObject = this; AddRef(); return S_OK; }
else return E_NOINTERFACE;
}
STDMETHOD(ContextSensitiveHelp) (BOOL fEnterMode) { return E_NOTIMPL; }
STDMETHOD(DeleteObject) (LPOLEOBJECT lpoleobj) { return E_NOTIMPL; }
STDMETHOD(GetClipboardData) (CHARRANGE FAR *lpchrg, DWORD reco, LPDATAOBJECT FAR *lplpdataobj) { return E_NOTIMPL; }
STDMETHOD(GetContextMenu) (WORD seltype, LPOLEOBJECT lpoleobj, CHARRANGE FAR *lpchrg, HMENU FAR *lphmenu) { return E_NOTIMPL; }
STDMETHOD(GetDragDropEffect) (BOOL fDrag, DWORD grfKeyState, LPDWORD pdwEffect) { return E_NOTIMPL; }
STDMETHOD(GetInPlaceContext) (LPOLEINPLACEFRAME FAR *lplpFrame, LPOLEINPLACEUIWINDOW FAR *lplpDoc, LPOLEINPLACEFRAMEINFO lpFrameInfo) { return E_NOTIMPL; }
STDMETHOD(GetNewStorage) (LPSTORAGE FAR *lplpstg);
STDMETHOD(QueryAcceptData) (LPDATAOBJECT lpdataobj, CLIPFORMAT FAR *lpcfFormat, DWORD reco, BOOL fReally, HGLOBAL hMetaPict) { return E_NOTIMPL; }
STDMETHOD(QueryInsertObject) (LPCLSID lpclsid, LPSTORAGE lpstg, LONG cp) { return S_OK; }
STDMETHOD(ShowContainerUI) (BOOL fShow) { return E_NOTIMPL; }
private:
udword mRefCounter;
};
{
// Initialize a Storage Object from a DocFile in memory
LPLOCKBYTES lpLockBytes = NULL;
SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
if (sc != S_OK) return sc;
sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, lplpstg);
if (sc != S_OK) lpLockBytes->Release();
return sc;
}
Originally posted by: Adrian Bacaianu
How to save the data in HTML format?
Hwo know a functions how convert the data between RTF and HTML?
Originally posted by: santosh
Hi,
I am getting resource leakage for IStorage & IOleObject. How do I remove it.
With regards
A.Santosh
Reply
Originally posted by: Phong Tran
Hi all
In my program, I use a RichEditCtrl (m_pRichEdit).
When I insert bitmap in loop
pRichEditOle = m_pRichEdit.GetIRichEditOle();
for ( int i = 0 ; i < 500; i++) // loop 500 times
{
m_pRichEdit.SetWindowText("");
for (int j=0; j < 100; j++ )
CImageDataObject::InsertBitmap(pRichEditOle, hBitmap);
//Insert about 100 bitmaps into m_pRichEdit.
}
Then Windows shows error :
"Not enough storage is available to the complete this operation"
I think that this program dont release memory (OLE Object) when I clear content of the RichEditCtrl (m_pRichEdit).
Please update the code at function
CImageDataObject::InsertBitmap(pRichEditOle, hBitmap)
{
...
// Release all unnecessary interfaces
pOleObject->Release();
pOleClientSite->Release();
lpLockBytes->Release(); // Please insert this line
pStorage->Release();
lpDataObject->Release();
}
Thanks in advance
Quoc Phong
my mail : tqp_vn@yahoo.com
p/s : About my comment "How to work in multithread"
One way to solve multithreaded
by sending a user define message that tells it to insert the text.. This method is the easiest method..
Thanks Hani Atassi. ;-)