HRESULT STDMETHODCALLTYPE TinySmiley::SaveAs(LPSTREAM pStm)//默认保存第一帧到文件流 { if (!pStm) return S_FALSE; if (m_images.size() == 0) return S_FALSE; BITMAP bitmap = { 0 }; if (!GetObject(m_images[0], sizeof(BITMAP), (LPSTR)&bitmap)) return S_FALSE; BITMAPINFOHEADER bi = { 0 }; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bitmap.bmWidth; bi.biHeight = bitmap.bmHeight; bi.biPlanes = 1; bi.biBitCount = bitmap.bmBitsPixel; bi.biCompression = BI_RGB; DWORD size = bitmap.bmWidthBytes * bitmap.bmHeight; BITMAPFILEHEADER bfh = { 0 }; bfh.bfType = 0x4d42; bfh.bfOffBits = min(14, sizeof(BITMAPFILEHEADER)) + sizeof(BITMAPINFOHEADER) + bi.biClrUsed * sizeof(RGBQUAD); bfh.bfSize = bfh.bfOffBits + bitmap.bmWidthBytes*bitmap.bmHeight; ULARGE_INTEGER libSize; libSize.LowPart = bfh.bfSize; pStm->SetSize(libSize); ULONG cbWritten = 0; pStm->Write(&bfh, min(14, sizeof(BITMAPFILEHEADER)), &cbWritten); pStm->Write(&bi, bi.biSize, &cbWritten); pStm->Write(bitmap.bmBits, bitmap.bmWidthBytes*bitmap.bmHeight, &cbWritten); return S_OK; }
STDMETHODIMP CValueAxis::Save(LPSTREAM pStm, BOOL fClearDirty) { pStm->Write(&m_iWholeDigits, sizeof(int), NULL); pStm->Write(&m_iDecimalDigits, sizeof(int), NULL); pStm->Write(&m_dMinVal, sizeof(double), NULL); pStm->Write(&m_dMaxVal, sizeof(double), NULL); return CAxis::Save(pStm, fClearDirty); }
STDMETHODIMP CAxis::Save(LPSTREAM pStm, BOOL fClearDirty) { m_bstrDisplayFormat.WriteToStream(pStm); m_bstrTitle.WriteToStream(pStm); pStm->Write(&m_lNumTicks, sizeof(m_lNumTicks), NULL); pStm->Write(&m_bShowAxis, sizeof(m_bShowAxis), NULL); pStm->Write(&m_bShowTitle, sizeof(m_bShowTitle), NULL); pStm->Write(&m_clrAxis, sizeof(m_clrAxis), NULL); pStm->Write(&m_clrTitle, sizeof(m_clrTitle), NULL); SaveFontToStream(m_spTickFont, pStm); SaveFontToStream(m_spTitleFont, pStm); return S_OK; }
FARINTERNAL UtDIBFileStmToPBrushNativeStm (LPSTREAM pstmDIBFile, LPSTREAM pstmPBrush) { BITMAPFILEHEADER bfh; HRESULT error; if (error = pstmDIBFile->Read(&bfh, sizeof(bfh), 0)) return error; // seek to the begining of the stream LARGE_INTEGER large_int; LISet32( large_int, 0); if (error = pstmDIBFile->Seek(large_int, STREAM_SEEK_SET, 0)) return error; if (error = pstmPBrush->Write(&(bfh.bfSize), sizeof(DWORD), 0)) return error; ULARGE_INTEGER ularge_int; ULISet32(ularge_int, bfh.bfSize); if ((error = pstmDIBFile->CopyTo(pstmPBrush, ularge_int, NULL, NULL)) == NOERROR) StSetSize(pstmPBrush, 0, TRUE); return error; }
FARINTERNAL UtPlaceableMFStmToMSDrawNativeStm (LPSTREAM pstmPMF, LPSTREAM pstmMSDraw) { DWORD dwSize; // size of metafile bits excluding the placeable MF header LONG xExt; LONG yExt; WORD wBuf[5]; // dwSize(DWORD), mm(int), xExt(int), yExt(int) HRESULT error; if (error = UtGetSizeAndExtentsFromPlaceableMFStm(pstmPMF, &dwSize, &xExt, &yExt)) return error; *((DWORD FAR*) wBuf) = dwSize + 3*sizeof(WORD); wBuf[2] = MM_ANISOTROPIC; wBuf[3] = (int) xExt; wBuf[4] = (int) yExt; if (error = pstmMSDraw->Write(wBuf, sizeof(wBuf), 0)) return error; ULARGE_INTEGER ularge_int; ULISet32(ularge_int, dwSize); if ((error = pstmPMF->CopyTo(pstmMSDraw, ularge_int, NULL, NULL)) == NOERROR) StSetSize(pstmMSDraw, 0, TRUE); return error; }
STDMETHODIMP CTimeAxis::Save(LPSTREAM pStm, BOOL fClearDirty) { double dTimeSpan = m_dMaxVal - m_dMinVal; pStm->Write(&dTimeSpan, sizeof(double), NULL); return CAxis::Save(pStm, fClearDirty); }
bool MAPIContact::SetNotes(const String &szNotes, bool bRTF) { #ifdef _WIN32_WCE return SetPropertyString(PR_BODY, szNotes); #else if(!Contact() || IsNull(szNotes)) return false; ULONG nLen = (ULONG)szNotes.GetLength(); HRESULT hr = E_FAIL; LPSTREAM pStream = NULL; if(bRTF) { if(Contact()->OpenProperty(PR_RTF_COMPRESSED, &IID_IStream, STGM_CREATE | STGM_WRITE, MAPI_MODIFY | MAPI_CREATE, (LPUNKNOWN*)&pStream) == S_OK) { IStream *pUncompressed; if(WrapCompressedRTFStream(pStream,MAPI_MODIFY, &pUncompressed) == S_OK) { hr = pUncompressed->Write(szNotes, nLen*sizeof(TCHAR), NULL); if(pUncompressed->Commit(STGC_DEFAULT)==S_OK) pStream->Commit(STGC_DEFAULT); RELEASE(pUncompressed); } } } else { if(Contact()->OpenProperty(PR_BODY, &IID_IStream, 0, MAPI_MODIFY | MAPI_CREATE, (LPUNKNOWN*)&pStream) == S_OK) hr = pStream->Write(szNotes, (nLen+1)*sizeof(TCHAR), NULL); } RELEASE(pStream); return (hr == S_OK); #endif }
STDMETHODIMP CGrid::Save(LPSTREAM pStm, BOOL fClearDirty) { pStm->Write(&m_bShowVertical, sizeof(m_bShowVertical), NULL); pStm->Write(&m_bShowHorizontal, sizeof(m_bShowHorizontal), NULL); pStm->Write(&m_lNumberOfVerticalLines, sizeof(m_lNumberOfVerticalLines), NULL); pStm->Write(&m_lNumberOfHorizontalLines, sizeof(m_lNumberOfHorizontalLines), NULL); pStm->Write(&m_enumVerticalStyle, sizeof(m_enumVerticalStyle), NULL); pStm->Write(&m_enumHorizontalStyle, sizeof(m_enumHorizontalStyle), NULL); pStm->Write(&m_nWidth, sizeof(m_nWidth), NULL); pStm->Write(&m_clrVerticalColor, sizeof(m_clrVerticalColor), NULL); pStm->Write(&m_clrHorizontalColor, sizeof(m_clrHorizontalColor), NULL); return S_OK; }
HRESULT CGifSmileyCtrl::IPersistStreamInit_Save(LPSTREAM pStm, BOOL fClearDirty,const ATL_PROPMAP_ENTRY* pMap) { INFO_GIF infoGif;; wsprintf(infoGif.filePath, m_strFilename.GetBuffer()); infoGif.hwndFrom = (LONG)m_hwndParent; infoGif.clrBackground = m_clrBackColor; pStm->Write(&infoGif, sizeof(INFO_GIF),NULL); return IPersistStreamInitImpl<CGifSmileyCtrl>::IPersistStreamInit_Save( pStm, fClearDirty, pMap); }
HRESULT CDrawMenu::DoSave(DWORD dwVer, LPSTREAM pStm) { pStm->Write(&m_bButtonDisplayed, sizeof(m_bButtonDisplayed), NULL); m_bstrButtonCaption.WriteToStream(pStm); int nCount = m_arrItems.GetSize(); pStm->Write(&nCount, sizeof(nCount), NULL); for (int i = 0; i < nCount; i++) { CMenuItem& item = m_arrItems[i]; item.m_bstrText.WriteToStream(pStm); pStm->Write(&item.m_dwState, sizeof(DWORD), NULL); if (dwVer > _SUPERCX_VER_0203) { item.m_bstrID.WriteToStream(pStm); pStm->Write(&item.m_dwShiftState, sizeof(DWORD), NULL); pStm->Write(&item.m_dwKeyCode, sizeof(DWORD), NULL); } } pStm->Write(&m_rcPosition, sizeof(m_rcPosition), NULL); m_bstrDescription.WriteToStream(pStm); return CCxDrawObjectBase::DoSave(dwVer, pStm); }
STDMETHODIMP CDrawTxt::SaveOldVer(LPSTREAM pStm, BOOL fClearDirty) { // pStm->Write(&m_bAutoSize, sizeof(BOOL), NULL); pStm->Write(&m_dFontHeight, sizeof(double), NULL); pStm->Write(&m_dFontWidth, sizeof(double), NULL); pStm->Write(&m_lWeight, sizeof(long), NULL); pStm->Write(&m_bItalic, sizeof(BOOL), NULL); pStm->Write(&m_bUnderLine, sizeof(BOOL), NULL); pStm->Write(&m_bStrikethrough, sizeof(BOOL), NULL); m_bstrFontName.WriteToStream(pStm); m_bstrCaption.WriteToStream(pStm); pStm->Write(&m_clrForeColor, sizeof(OLE_COLOR), NULL); pStm->Write(&m_clrBackColor, sizeof(OLE_COLOR), NULL); pStm->Write(&m_nTextAlign, sizeof(UINT), NULL); pStm->Write(&m_bsBackStyle, sizeof(enumBackStyle), NULL); pStm->Write(&m_rcPosition, sizeof(RECTF), NULL); return ICxDrawObjectImpl<CDrawTxt>::SaveOldVer(pStm, fClearDirty); }
// -------------------------------------------------------------------------------------------- // fClearDirty: Zustand im aktuellen Projekt und dessen Abspeicherung ist identisch (true) bzw. // stimmt nicht überein (false); letzterer Fall tritt bei SaveAs() auf STDMETHODIMP CRegOperatPropAct::Save (LPSTREAM pStm, BOOL fClearDirty) { // Bezeichner wegschreiben HRESULT hr = CPropertyAction::Save (pStm, fClearDirty); if (FAILED(hr)) return hr; // Signatur und Version wegschreiben DWORD dwSignature = REGOPERATPROPACT_SIGNATURE; DWORD dwVersion = REGOPERATPROPACT_VERSION_1_0_2; RETURN_FAILED_HRESULT (pStm->Write (&dwSignature, sizeof(DWORD), NULL)); RETURN_FAILED_HRESULT (pStm->Write (&dwVersion, sizeof(DWORD), NULL)); // dann selektierte Info der letzten Auswahl // nachfolgende if-Bedingung für den Fall, daß m_pRegOperDlg-Seite "am Schluß" nicht oben // lag, also BeginAction() und damit auch GetSelectedInfo() nicht ausgeführt wurden if (m_pRegOperDlg) m_pRegOperDlg->GetSelectedInfo (&m_caSelInfo, m_bIsDirty); RETURN_FAILED_HRESULT (pStm->Write (&m_caSelInfo.bClassKey, sizeof(BOOL), NULL)); RETURN_FAILED_HRESULT (pStm->Write (&m_caSelInfo.bInter, sizeof(BOOL), NULL)); RETURN_FAILED_HRESULT (pStm->Write (&m_caSelInfo.bExter, sizeof(BOOL), NULL)); RETURN_FAILED_HRESULT (pStm->Write (&m_caSelInfo.bBound, sizeof(BOOL), NULL)); if (!m_mkOperOptions.IsValid() && m_wOperOptions.IsValid()) { // ggf. Moniker geben lassen RETURN_FAILED_HRESULT (MkGetMoniker(m_wOperOptions, OLEGETMONIKER_FORCEASSIGN, OLEWHICHMK_OBJFULL, m_mkOperOptions.ppi())); } // und Moniker wegschreiben BOOL fHasMoniker; if (m_mkOperOptions.IsValid()) { fHasMoniker = TRUE; RETURN_FAILED_HRESULT (pStm->Write (&fHasMoniker, sizeof(BOOL), NULL)); RETURN_FAILED_HRESULT (OleSaveToStream(WPersistStream(m_mkOperOptions), pStm)); } else { fHasMoniker = FALSE; RETURN_FAILED_HRESULT (pStm->Write (&fHasMoniker, sizeof(BOOL), NULL)); } if (fClearDirty) m_bIsDirty = false; return S_OK; } // Save
STDMETHODIMP CPoint::IMyPersistStreamImpl_Save(LPSTREAM pIStream, BOOL /*fClearDirty */) { ULONG cb; HRESULT hr; if (NULL==pIStream) return ResultFromScode(E_POINTER); // // Write the object into the stream. // hr=pIStream->Write(&m_Point, (ULONG)sizeof(POINT), &cb); if (FAILED(hr) || sizeof(POINT)!=cb) return ResultFromScode(STG_E_WRITEFAULT); return NOERROR; }
BOOL AFXAPI _AfxInitStreamDataFromBlobProp(LPSTREAM pstm, CProperty* pprop) { BOOL bSuccess = FALSE; ULONG cb; BYTE* pbData = (BYTE*)(pprop->Get(&cb)); if (pbData != NULL) { // Put the data into the stream, then seek back to start of data. LARGE_INTEGER liOffset; liOffset.LowPart = -(LONG)cb; liOffset.HighPart = -1; if (SUCCEEDED(pstm->Write(pbData + sizeof(ULONG), cb, NULL)) && SUCCEEDED(pstm->Seek(liOffset, STREAM_SEEK_CUR, NULL))) { bSuccess = TRUE; } } return bSuccess; }
void ReadDirectory(const char* szPath, LPSTORAGE pStg) { // recursive function USES_CONVERSION; WIN32_FIND_DATA fData; HANDLE h; char szNewPath[MAX_PATH]; char szStorageName[100]; char szStreamName[100]; char szData[81]; char* pch = NULL; LPSTORAGE pSubStg = NULL; LPSTREAM pStream = NULL; g_nIndent++; strcpy(szNewPath, szPath); strcat(szNewPath, "*.*"); h = ::FindFirstFile(szNewPath, &fData); if (h == (HANDLE) 0xFFFFFFFF) return; // can't find directory do { if (!strcmp(fData.cFileName, "..") || !strcmp(fData.cFileName, ".") ) continue; while((pch = strchr(fData.cFileName, '!')) != NULL) { *pch = '|'; } if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // It's a directory, so make a storage strcpy(szNewPath, szPath); strcat(szNewPath,fData.cFileName); strcat(szNewPath, "\\"); strcpy(szStorageName, fData.cFileName); szStorageName[31] = '\0'; // limit imposed by OLE TRACE("%0.*sStorage = %s\n", (g_nIndent - 1) * 4, g_szBlanks, szStorageName); VERIFY(pStg->CreateStorage(T2COLE(szStorageName), STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pSubStg) == S_OK); ASSERT(pSubStg != NULL); ReadDirectory(szNewPath, pSubStg); pSubStg->Release(); } else { if ((pch = strrchr(fData.cFileName, '.')) != NULL) { if (!stricmp(pch, ".TXT")) { // It's a text file, so make a stream strcpy(szStreamName, fData.cFileName); strcpy(szNewPath, szPath); strcat(szNewPath, szStreamName); szStreamName[32] = '\0'; // OLE max length TRACE("%0.*sStream = %s\n", (g_nIndent - 1) * 4, g_szBlanks, szNewPath); CStdioFile file(szNewPath, CFile::modeRead); // Ignore zero-length files if(file.ReadString(szData, 80)) { TRACE("%s\n", szData); VERIFY(pStg->CreateStream(T2COLE(szStreamName), STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream) == S_OK); ASSERT(pStream != NULL); // Include the null terminator in the stream pStream->Write(szData, strlen(szData) + 1, NULL); pStream->Release(); } } } } } while (::FindNextFile(h, &fData)); g_nIndent--; }
HRESULT CDrawTxt::DoSave(DWORD dwVer, LPSTREAM pStm) { pStm->Write(&m_enumMousePointer, sizeof(m_enumMousePointer), NULL); m_bstrDescription.WriteToStream(pStm); pStm->Write(&m_dFontHeight, sizeof(double), NULL); pStm->Write(&m_dFontWidth, sizeof(double), NULL); pStm->Write(&m_lWeight, sizeof(long), NULL); pStm->Write(&m_bItalic, sizeof(BOOL), NULL); pStm->Write(&m_bUnderLine, sizeof(BOOL), NULL); pStm->Write(&m_bStrikethrough, sizeof(BOOL), NULL); m_bstrFontName.WriteToStream(pStm); m_bstrCaption.WriteToStream(pStm); pStm->Write(&m_clrForeColor, sizeof(OLE_COLOR), NULL); pStm->Write(&m_clrBackColor, sizeof(OLE_COLOR), NULL); pStm->Write(&m_nTextAlign, sizeof(UINT), NULL); pStm->Write(&m_bsBackStyle, sizeof(enumBackStyle), NULL); pStm->Write(&m_rcPosition, sizeof(RECTF), NULL); if (dwVer > _SUPERCX_VER_0207) { pStm->Write(&m_bAutoSize, sizeof(BOOL), NULL); pStm->Write(&m_bWordWrap, sizeof(BOOL), NULL); } return CCxDrawObjectBase::DoSave(dwVer, pStm); }
STDMETHODIMP CDirectDynamic::Save(LPSTREAM pStm, BOOL fClearDirty) { m_bstrSource.WriteToStream(pStm); pStm->Write(&m_bEnableMouseInput, sizeof(m_bEnableMouseInput), NULL); return S_OK; }
void CModuleWnd::GetDragInfoData(LPSTGMEDIUM lpStgMedium) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); int nItem; CModuleDoc::CModule* pModule; CRect rcBound; rcBound.SetRectEmpty(); CClientDC dc(this); dc.BeginPath(); POSITION pos = GetListCtrl()->GetFirstSelectedItemPosition(); while (pos) { nItem = GetListCtrl()->GetNextSelectedItem(pos); pModule = m_pCurrentDocument->GetModule(nItem); CRect rcObj = pModule->m_rcPosition.GetRECT(); rcObj.NormalizeRect(); rcBound.UnionRect(rcBound, rcObj); dc.MoveTo(rcObj.left, rcObj.top); dc.LineTo(rcObj.right, rcObj.top); dc.LineTo(rcObj.right, rcObj.bottom); dc.LineTo(rcObj.left, rcObj.bottom); dc.LineTo(rcObj.left, rcObj.top); } dc.EndPath(); CPoint ptStart = rcBound.CenterPoint(); theApp.AlignToGrid(ptStart); LPSTREAM lpStream; if (::CreateStreamOnHGlobal(NULL, TRUE, &lpStream) != S_OK) AfxThrowMemoryException(); ASSERT(lpStream != NULL); lpStream->Write(&rcBound, sizeof(CRect), NULL); lpStream->Write(&ptStart, sizeof(CPoint), NULL); int iNumPoints = dc.GetPath(NULL, NULL, 0); CPoint* pPoints = new CPoint[iNumPoints]; if (pPoints == NULL) AfxThrowMemoryException(); BYTE* pTypes = new BYTE[iNumPoints]; if (pTypes == NULL) AfxThrowMemoryException(); iNumPoints = dc.GetPath(pPoints, pTypes, iNumPoints); lpStream->Write(&iNumPoints, sizeof(int), NULL); lpStream->Write(pPoints, sizeof(CPoint) * iNumPoints, NULL); lpStream->Write(pTypes, sizeof(BYTE) * iNumPoints, NULL); if (pPoints != NULL) delete pPoints; if (pTypes != NULL) delete pTypes; // setup the STGMEDIUM lpStgMedium->tymed = TYMED_ISTREAM; lpStgMedium->pstm = lpStream; lpStgMedium->pUnkForRelease = NULL; }
HRESULT CDrawEllipse::DoSave(DWORD dwVer, LPSTREAM pStm) { pStm->Write(&m_enumFillStyle, sizeof(m_enumFillStyle), NULL); pStm->Write(&m_enumHorFillDirection, sizeof(m_enumHorFillDirection), NULL); pStm->Write(&m_enumVerFillDirection, sizeof(m_enumVerFillDirection), NULL); pStm->Write(&m_nHorFillPercent, sizeof(m_nHorFillPercent), NULL); pStm->Write(&m_nVerFillPercent, sizeof(m_nVerFillPercent), NULL); m_BrushImageFileName.WriteToStream(pStm); pStm->Write(&m_clrFillColor, sizeof(m_clrFillColor), NULL); pStm->Write(&m_clrHighLightFill, sizeof(m_clrHighLightFill), NULL); pStm->Write(&m_enumEdgeStyle, sizeof(m_enumEdgeStyle), NULL); pStm->Write(&m_fEdgeWidth, sizeof(m_fEdgeWidth), NULL); pStm->Write(&m_enumLineJoinStyle, sizeof(m_enumLineJoinStyle), NULL); pStm->Write(&m_clrEdgeColor, sizeof(m_clrEdgeColor), NULL); pStm->Write(&m_clrHighLightEdge, sizeof(m_clrHighLightEdge), NULL); pStm->Write(&m_ptRotateBase, sizeof(m_ptRotateBase), NULL); pStm->Write(&m_enumScaleBase, sizeof(m_enumScaleBase), NULL); pStm->Write(&m_enumMousePointer, sizeof(m_enumMousePointer), NULL); m_bstrDescription.WriteToStream(pStm); return CCxDrawObjectBase::DoSave(dwVer, pStm); }