alexey_ma |
16.06.2004 16:47 |
Картинки можно рисовать. Только гиморойно. И еще нажно будет проверять какая версия riched.dll стоит в системе. Если это riched20.dll -то все впорядке с картинками можно работать(это версия 2). Версия 1 -помоему картинки (да и таблицы) не поддерживает. Есть шанс нарватся на такие проблемы в Win95/98/NT.
По мне так лучше НТМL использовать для таких вещей. Он и таблицы и картинки и все что угодно показывает. И работать с ним через DOM достаточно просто.
Ну и чтоб жизнь медом не казалась вот пример функции которая вставляет bmp из файла в ричедит. Написано на VC 6
Код:
void CXXX::InsertFile(const CString& strFileName,CRichEditCtrl* pRichEdit)
{
LPSTORAGE m_lpStorage = NULL; // provides storage for m_lpObject
LPLOCKBYTES m_lpLockBytes = NULL; // part of implementation of m_lpStorage
LPOLEOBJECT m_lpObject = NULL; // in case you want direct access to the OLE object
LPVIEWOBJECT2 m_lpViewObject = NULL; // IViewObject for IOleObject above
USES_CONVERSION;
SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &m_lpLockBytes);
if (sc != S_OK)
AfxThrowOleException(sc);
ASSERT(m_lpLockBytes != NULL);
sc = ::StgCreateDocfileOnILockBytes(m_lpLockBytes,
STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage);
if (sc != S_OK)
{
if (m_lpStorage)
{
STATSTG pstatstg;
HRESULT hR1 = m_lpStorage->Stat(&pstatstg,STATFLAG_DEFAULT); //Values taken from the STATFLAG enumeration
m_lpStorage->DestroyElement(pstatstg.pwcsName);
m_lpStorage->Release();
m_lpStorage = NULL;
}
if (m_lpLockBytes)
{
m_lpLockBytes->Release();
m_lpLockBytes = NULL;
}
AfxThrowOleException(sc);
return;
}
CString szFileName( strFileName );
// attempt to create the object
sc = ::OleCreateFromFile(CLSID_NULL, T2COLE(szFileName),
IID_IUnknown, OLERENDER_DRAW, NULL, NULL,
m_lpStorage, (void **)&m_lpObject);
if ( sc != S_OK )
{
TCHAR * lpMsgBuf;
::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM, NULL,
::GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL );
CString msg( lpMsgBuf );
msg += _T("xxxxxxxxxxxxxxxxxxx" );
msg += szFileName;
AfxMessageBox( msg, MB_OK );
::LocalFree( lpMsgBuf );
if (m_lpObject != NULL)
{
OleFlushClipboard( );
LPUNKNOWN lpUnk = m_lpObject;
m_lpObject = QUERYINTERFACE(lpUnk, IOleObject);
CoDisconnectObject(lpUnk,0);
m_lpObject->Close(OLECLOSE_NOSAVE );
lpUnk->Release();
m_lpObject->Release();
m_lpObject = NULL;
lpUnk = NULL;
}
if (m_lpStorage)
{
STATSTG pstatstg;
HRESULT hR1 = m_lpStorage->Stat(&pstatstg,STATFLAG_DEFAULT); //Values taken from the STATFLAG enumeration
m_lpStorage->DestroyElement(pstatstg.pwcsName);
m_lpStorage->Release();
m_lpStorage = NULL;
}
if (m_lpLockBytes)
{
m_lpLockBytes->Release();
m_lpLockBytes = NULL;
}
AfxThrowOleException(E_OUTOFMEMORY);
return;
}//end if ( sc != S_OK )
// m_lpObject is currently an IUnknown, convert to IOleObject
if (m_lpObject != NULL)
{
LPUNKNOWN lpUnk = m_lpObject;
m_lpObject = QUERYINTERFACE(lpUnk, IOleObject);
lpUnk->Release();
lpUnk = NULL;
if (m_lpObject == NULL)
AfxThrowOleException(E_OUTOFMEMORY);
}
// cache the IViewObject interface
m_lpViewObject = QUERYINTERFACE(m_lpObject, IViewObject2);
if (m_lpViewObject == NULL)
{
if (m_lpObject != NULL)
{
OleFlushClipboard( );
LPUNKNOWN lpUnk = m_lpObject;
m_lpObject = QUERYINTERFACE(lpUnk, IOleObject);
CoDisconnectObject(lpUnk,0);
m_lpObject->Close(OLECLOSE_NOSAVE );
lpUnk->Release();
m_lpObject->Release();
m_lpObject = NULL;
lpUnk = NULL;
}
if (m_lpStorage)
{
STATSTG pstatstg;
HRESULT hR1 = m_lpStorage->Stat(&pstatstg,STATFLAG_DEFAULT); //Values taken from the STATFLAG enumeration
m_lpStorage->DestroyElement(pstatstg.pwcsName);
m_lpStorage->Release();
m_lpStorage = NULL;
}
if (m_lpLockBytes)
{
m_lpLockBytes->Release();
m_lpLockBytes = NULL;
}
return;
}
// setup for advises; we assume that OLE cleans them up properly
LPADVISESINK lpAdviseSink =
(LPADVISESINK)pRichEdit->GetInterface(&IID_IAdviseSink);
// set up view advise
VERIFY(m_lpViewObject->SetAdvise(DVASPECT_CONTENT, 0, lpAdviseSink)
== S_OK);
// the server shows these in its user-interface
// (as document title and in File Exit menu)
m_lpObject->SetHostNames(T2COLE(AfxGetAppName()),
T2COLE(_T("Test")));
// all items are "contained" -- this makes our reference to this object
// weak -- which is needed for links to embedding silent update.
OleSetContainedObject(m_lpObject, TRUE);
CHARRANGE cr;
pRichEdit->GetSel( cr );
cr.cpMin = cr.cpMax -1;
pRichEdit->SetSel( cr );
REOBJECT reo;
memset( &reo, 0, sizeof( reo ) );
reo.cbStruct = sizeof( reo );
CLSID classID;
if ( m_lpObject->GetUserClassID( &classID ) != S_OK)
classID = CLSID_NULL;
reo.clsid = classID;
reo.cp = REO_CP_SELECTION;
reo.poleobj = m_lpObject;
reo.pstg = m_lpStorage;
LPOLECLIENTSITE lpClientSite = NULL;
pRichEdit->GetIRichEditOle()->GetClientSite( &lpClientSite );
reo.polesite = lpClientSite;
SIZEL sizel;
sizel.cx = sizel.cy = 0; // let richedit determine initial size
reo.sizel = sizel;
reo.dvaspect = DVASPECT_CONTENT;
reo.dwFlags = REO_RESIZABLE;
reo.dwUser = 0;
HRESULT hr = pRichEdit->GetIRichEditOle()->InsertObject( &reo );
if (m_lpObject != NULL)
{
OleFlushClipboard( );
LPUNKNOWN lpUnk = m_lpObject;
m_lpObject = QUERYINTERFACE(lpUnk, IOleObject);
CoDisconnectObject(lpUnk,0);
lpClientSite->OnShowWindow(FALSE);
m_lpObject->Close(OLECLOSE_NOSAVE );
lpUnk->Release();
m_lpObject->Release();
m_lpObject = NULL;
lpUnk = NULL;
}
else
AfxThrowOleException(E_OUTOFMEMORY);
if (m_lpStorage)
{
STATSTG pstatstg;
HRESULT hR1 = m_lpStorage->Stat(&pstatstg,STATFLAG_DEFAULT); //Values taken from the STATFLAG enumeration
m_lpStorage->DestroyElement(pstatstg.pwcsName);
m_lpStorage->Release();
m_lpStorage = NULL;
}
if (m_lpLockBytes)
{
m_lpLockBytes->Release();
m_lpLockBytes = NULL;
}
if (m_lpObject)
{
m_lpObject->Release();
m_lpObject = NULL;
}
if (m_lpViewObject)
{
m_lpViewObject->Release();
m_lpViewObject = NULL;
}
if (lpAdviseSink)
{
lpAdviseSink->Release();
lpAdviseSink = NULL;
}
if (lpClientSite)
{
lpClientSite->Release();
lpClientSite = NULL;
}
return;
}
Еще, как вариант, можно в принципе попробовать вставить в твою форму Word как ActiveX control и им рулить через его интерфейсы, с таблицами и картинками в Word проблем быть не должно.
|