Exemple #1
0
RImage* QSLItemData::Load2(
	LPSTORAGE	pIStorage,			// @parm storage
	BOOL        fDescOnly )
{
	RImage* pImage = NULL;
	char	strDescription[kBufLength];

	TRY
	{
		COleStreamFile  str;

		if (!fDescOnly)
		{
			// open stream
			CString  szStream = "PREVIEW";

			if (str.OpenStream (pIStorage, szStream, CFile::modeRead | CFile::shareExclusive))
			{
				// Read in the image data
				RTempFileBuffer	buffer;
				buffer.Resize( str.GetLength() );
				str.Read( buffer.GetBuffer(), str.GetLength() );
				str.Close();

				// Create the image
				pImage = RImageLibrary().ImportImage( buffer );
			}
		}

		if (fDescOnly)
		{
			// open stream
			CString szStream = "DESCRIPTION";

			if (str.OpenStream (pIStorage, szStream, CFile::modeRead | CFile::shareExclusive))
			{
				str.Read (&strDescription, min( kBufLength, str.GetLength() ));
				str.Close();
			}

			// return bitmap handle and description string
			m_strDesc = strDescription;
		}

	} // End try

	CATCH(CArchiveException, archExcept)
	{
		//CBExceptionReporter::ArchiveException(archExcept);
	}
	END_CATCH


	return pImage;
}
Exemple #2
0
void COleDocument::LoadFromStorage()
{
	ASSERT(m_lpRootStg != NULL);

	// open Contents stream
	COleStreamFile file;
	CFileException fe;
	if (!file.OpenStream(m_lpRootStg, _T("Contents"),
			CFile::modeRead|CFile::shareExclusive, &fe) &&
		!file.CreateStream(m_lpRootStg, _T("Contents"),
			CFile::modeRead|CFile::shareExclusive|CFile::modeCreate, &fe))
	{
		if (fe.m_cause == CFileException::fileNotFound)
			AfxThrowArchiveException(CArchiveException::badSchema);
		else
			AfxThrowFileException(fe.m_cause, fe.m_lOsError);
	}

	// load it with CArchive (loads from Contents stream)
	CArchive loadArchive(&file, CArchive::load | CArchive::bNoFlushOnDelete);
	loadArchive.m_pDocument = this;
	loadArchive.m_bForceFlat = FALSE;

	TRY
	{
		if (file.GetLength() != 0)
			Serialize(loadArchive);     // load main contents
		loadArchive.Close();
		file.Close();
	}
	CATCH_ALL(e)
	{
		file.Abort();   // will not throw an exception
		DeleteContents();   // removed failed contents
		NO_CPP_EXCEPTION(loadArchive.Abort());
		THROW_LAST();
	}
	END_CATCH_ALL
}
Exemple #3
0
BOOL CFormObj::CreateFromSubDocumentClipboard(CArchive& ar, IStorage* pStorage)
{
	USES_CONVERSION;
	HRESULT hResult;
	TCHAR szDocumentName[64];
	IStoragePtr pSubStorage;

	ASSERT_VALID(this);
	ASSERT(ar.IsLoading());
	
	m_dwObjectNumber = GetNewObjectNumber();

	CString strName;
	ar >> strName;

	//用于确定所创建的子存储
	DWORD dwDocumentNumber;
	ar >> dwDocumentNumber;
	wsprintf(szDocumentName, _T("SubDoc%lu"), dwDocumentNumber);

	//打开子存储
	hResult = pStorage->OpenStorage(T2COLE(szDocumentName), NULL, STGM_READWRITE|
			STGM_SHARE_EXCLUSIVE, NULL, 0, &pSubStorage);
	if (FAILED(hResult))
	{
		AfxThrowOleException(hResult);
	}

	int bOpen;
	ar >> bOpen;

	if (bOpen)
	{
		//创建项目流
		COleStreamFile file;
		CFileException fe;
		if (!file.OpenStream(pSubStorage, _T("Contents"),
				CFile::modeRead|CFile::shareExclusive, &fe))
		{
			if (fe.m_cause == CFileException::fileNotFound)
				AfxThrowArchiveException(CArchiveException::badSchema);
			else
				AfxThrowFileException(fe.m_cause, fe.m_lOsError);
		}

		//保存到项目流
		CArchive loadArchive(&file, CArchive::load | CArchive::bNoFlushOnDelete);

		//注意CFormObj与CFormDoc的对等关系
		if (!CreateFormDoc())
			return FALSE;
	
		VERIFY(m_pFormDoc->CreateFromClipboard(loadArchive, pSubStorage) == TRUE);

		loadArchive.Flush();
		file.Close();
	}
	else
	{
		//注意CFormObj与CFormDoc的对等关系
		if (!CreateFormDoc())
			return FALSE;
		
		m_pFormDoc->ReadFromStorage(pSubStorage);
	}

	// 2004.8.10 remove flow 2 lines
//	CRectF position = m_pFormDoc->m_position;
//	MoveTo(position, FALSE);

	// 2004.8.10 add flow 1 lines
	m_position = m_pFormDoc->m_position;

	m_ptRotateBase = m_position.CenterPoint();

	if (!PutDisplayName(strName))
	{
		CString strBaseName = strName;
		RemoveRightDigits(strBaseName);

		m_pDocument->CreateUniqueObjectName(this, (IsBaseObject() || strBaseName.IsEmpty()) ? LPCTSTR(NULL) : strBaseName); // 使用源对象名字作为基本名
	}
	
	return TRUE;
}