none
windowsleass中的richedit无法保存ole图片到rtf RRS feed

  • 问题

  • 我特意分析了保存后的rtf格式,每次保存的图片都是一样的数据格式:

    {\pict\wmetafile8\picw635\pich635\picwgoal360\pichgoal360 
    010009000003160000000000050000000000050000000b0200000000050000000c027b027b0203
    0000000000
    }

    按照常理16进制的数据应该很大才对图片来说,不知道哪里做错了~~  以下是我的保存代码:

    	BSTR bstrFileName = NULL;
    	IStorage* lpStorage =NULL;
    	LPLOCKBYTES  lpLockBytes  = NULL;//LOCKBYTE
    	IRichEditOle * pRichEditOle = NULL;
    	IOleClientSite *pOleClientSite = NULL;
    	IImageOle* pImageOle = NULL;
    	IOleObject *pOleObject = NULL;
    	REOBJECT reobject = {0};
    	HRESULT hr = E_FAIL;
    	CLSID	clsid;
    
    	if (NULL == pTextServices || NULL == pTextHost ||
    		NULL == lpszFileName || NULL == *lpszFileName)
    		return FALSE;
    
    	TCHAR cProtocol[16] = {0};
    	_tcsncpy(cProtocol, lpszFileName, 7);
    	if ((_tcsicmp(cProtocol, _T("http://")) != 0) && ::GetFileAttributes(lpszFileName) == 0xFFFFFFFF)
    		return FALSE;
    
    	bstrFileName = ::SysAllocString(lpszFileName);
    	if (NULL == bstrFileName)
    		return FALSE;
    
    	pTextServices->TxSendMessage(EM_GETOLEINTERFACE, 0, (LPARAM)&pRichEditOle, NULL);
    	if (NULL == pRichEditOle)
    		goto Ret0;
    
    	hr = ::CoCreateInstance(CLSID_ImageOle, NULL,CLSCTX_INPROC_SERVER, IID_IImageOle, (void**)&pImageOle);
    	if (FAILED(hr))
    		goto Ret0;
    
    	hr = pImageOle->QueryInterface(IID_IOleObject, (void **)&pOleObject);
    	if (FAILED(hr))
    		goto Ret0;
    
    	hr = pOleObject->GetUserClassID(&clsid);
    	if (FAILED(hr))
    	{
    	 	goto Ret0;
    	}
    
    	hr = ::CreateILockBytesOnHGlobal(NULL,TRUE,&lpLockBytes);//创建LOCKBYTE对象
    	if (FAILED(hr))
    		goto Ret0;
    
    	ASSERT(lpLockBytes != NULL);
    
    	hr = ::StgCreateDocfileOnILockBytes(lpLockBytes,STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage);
    	if (FAILED(hr))
    	{
    		lpLockBytes=NULL;
    
    		goto Ret0;
    	}
    
    	pRichEditOle->GetClientSite(&pOleClientSite);
    	if (NULL == pOleClientSite)
    		goto Ret0;
    
    	pOleObject->SetClientSite(pOleClientSite);
    
    	pImageOle->SetTextServices(pTextServices);
    	pImageOle->SetTextHost(pTextHost);
    	pImageOle->SetFaceId(nFaceId);
    	pImageOle->SetFaceIndex(nFaceIndex);
    	pImageOle->SetBgColor(clrBg);
    	pImageOle->SetAutoScale(bAutoScale, nReservedWidth);
    	pImageOle->LoadFromFile(bstrFileName);
    		
    	reobject.cbStruct = sizeof(REOBJECT);
    	reobject.clsid    = clsid/*CLSID_ImageOle*/;
    	reobject.cp       = REO_CP_SELECTION;
    	reobject.dvaspect = DVASPECT_CONTENT;
    	reobject.dwFlags  = REO_BELOWBASELINE;
    	reobject.poleobj  = pOleObject;
    	reobject.polesite = pOleClientSite;
    	reobject.pstg	  = lpStorage;//存储接口
    
    	hr = pRichEditOle->InsertObject(&reobject);
    	hr = ::OleSetContainedObject(pOleObject, TRUE);
    Ret0:
    	if (pOleObject != NULL)
    		pOleObject->Release();
    
    	if (pImageOle != NULL)
    		pImageOle->Release();
    
    	if (pOleClientSite != NULL)
    		pOleClientSite->Release();
    
    	if (pRichEditOle != NULL)
    		pRichEditOle->Release();
    
    	if (bstrFileName != NULL)
    		::SysFreeString(bstrFileName);
    
    	if (lpStorage!=NULL)
    	{
    		lpStorage->Release();
    	}
    
    	return SUCCEEDED(hr);

    2014年2月6日 13:00

答案

  • 你好,

    根据你的描述,请您参考以下链接中的代码示例。

    How to insert a bitmap into an RTF document using the RichEdit control in Visual C++ 6.0

    http://support.microsoft.com/kb/220844/en-us

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年2月7日 5:52

全部回复

  • 你好,

    根据你的描述,请您参考以下链接中的代码示例。

    How to insert a bitmap into an RTF document using the RichEdit control in Visual C++ 6.0

    http://support.microsoft.com/kb/220844/en-us

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年2月7日 5:52
  • 您好,您指的那个连接是保存bitmap的,这个我已经可以保存了,唯独是gif不能保存。gif是独立的ole对象
    2014年10月17日 8:09