예제 #1
0
int writeToDataObject(LPDATAOBJECT lpDataObject, UINT fid, std::istream& is, HWND hwnd, int bufsize)
{
	HANDLE hDib = 0;
	// The client placed the bitmap HANDLE in the stream
	// Note: the SController adds a trailing null char to the data (hence the +1)
	if ((bufsize) && (bufsize == sizeof (HANDLE) + 1)) 
    {
		HANDLE hBitmapTemp;		
		is.read ((char *)&hBitmapTemp, sizeof (HANDLE));		
		hDib = hBitmapTemp;
		//hDib = (HBITMAP)::OleDuplicateData (hBitmapTemp, Format::F_IGLAYER, 0);
    }
	
	if (hDib == 0)
	{
		return 0;
	}
	
	FORMATETC format;
	STGMEDIUM medium;
	ZeroMemory (&format, sizeof (format));
	ZeroMemory (&medium, sizeof (medium));
	
	format.cfFormat = static_cast<CLIPFORMAT> (fid);
	format.dwAspect = DVASPECT_CONTENT;
	format.ptd = 0;
	format.lindex = -1;
	medium.tymed = format.tymed = TYMED_HGLOBAL;
	medium.hGlobal = hDib;
	medium.pUnkForRelease = 0;
	
	lpDataObject->SetData (&format, &medium, TRUE);
	return 1;
}
예제 #2
0
파일: ctlpset.cpp 프로젝트: anyue100/winscp
BOOL AFXAPI _AfxLoadObjectFromStreamedPropset(LPUNKNOWN lpUnknown, LPSTREAM lpStream)
{
	ASSERT_POINTER(lpUnknown, IUnknown);
	ASSERT_POINTER(lpStream, IStream);

	BOOL bSuccess = FALSE;
	LPDATAOBJECT pDataObj = NULL;

	if (SUCCEEDED(lpUnknown->QueryInterface(IID_IDataObject,
			(LPVOID*)&pDataObj)))
	{
		ASSERT_POINTER(pDataObj, IDataObject);

		// Set the persistent propset format on the object.

		FORMATETC formatEtc;
		STGMEDIUM stgMedium;
		formatEtc.cfFormat = _AfxGetClipboardFormatPersistPropset();
		formatEtc.ptd = NULL;
		formatEtc.dwAspect = DVASPECT_CONTENT;
		formatEtc.lindex = -1;
		formatEtc.tymed = TYMED_ISTREAM;

		stgMedium.tymed = TYMED_ISTREAM;
		stgMedium.pstm = lpStream;
		stgMedium.pUnkForRelease = NULL;

		bSuccess = SUCCEEDED(pDataObj->SetData(&formatEtc, &stgMedium, FALSE));

		pDataObj->Release();
	}

	return bSuccess;
}