Example #1
0
void CGelView::OnEditCopy() 
{

	if ( !OpenClipboard() ) {
		AfxMessageBox("Cannot Open Clipboard", MB_OK | MB_ICONEXCLAMATION);
		return;
	}
	
	if ( !EmptyClipboard() ) {
		AfxMessageBox("Cannot Empty Clipboard", MB_OK | MB_ICONEXCLAMATION);
		return;
	}

	CGenedocDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	CDC* pDC = GetDC();

	double xpi = (double)pDC->GetDeviceCaps(HORZSIZE) / (double)pDC->GetDeviceCaps(HORZRES);
	double ypi = (double)pDC->GetDeviceCaps(VERTSIZE) / (double)pDC->GetDeviceCaps(VERTRES);

	double tXSize, tYSize;

	tXSize = GetGelSize().cx * xpi * 100.0;

	tYSize = GetGelSize().cy * ypi * 100.0;

	CRect rectView(0,0,(int)tXSize, (int)tYSize );

	CMetaFileDC dcMeta;

	dcMeta.CreateEnhanced(pDC, NULL, rectView, "GeneDoc\0MetaFile\0\0" );

	dcMeta.SetAttribDC( pDC->m_hAttribDC );


	OnPrepareDC( &dcMeta );

	DrawGel( &dcMeta, rectView );

	HENHMETAFILE hMeta = dcMeta.CloseEnhanced();


	if ( SetClipboardData(CF_ENHMETAFILE, hMeta) == NULL ) {
		AfxMessageBox( "Select Failed in SetClipBoardData", MB_OK | MB_ICONEXCLAMATION );
	}

// CBitmap
//
	if ( !CloseClipboard() ) {
		AfxMessageBox( "CloseClipboard Failed", MB_OK | MB_ICONEXCLAMATION );
	}

	ReleaseDC(pDC);	// Moved this down here so nt4.0 would work.
	return;

}
Example #2
0
void CFDMSView::OnEditCopy()
{

    if (testGraph)
    {
        CMetaFileDC * pMetaDC = new CMetaFileDC();
        pMetaDC->CreateEnhanced(GetDC(),NULL,NULL,testGraph->GetGraphTitle());
        //draw meta file

        //do what ever you want to do: bitmaps, lines, text...
        if (testGraph)
            testGraph->DrawGraph(pMetaDC);
        //close meta file dc and prepare for clipboard;
        HENHMETAFILE hMF = pMetaDC->CloseEnhanced();

        //copy to clipboard
        OpenClipboard();
        EmptyClipboard();
        ::SetClipboardData(CF_ENHMETAFILE,hMF);
        CloseClipboard();
        //DeleteMetaFile(hMF);
        delete pMetaDC;
    }
}
Example #3
0
void CMFCDCView::OnDcMetafiledc() 
{
	// TODO: Add your command handler code here
	//1 创建
	CMetaFileDC meta;
	meta.Create();
	//2 绘制
	meta.TextOut(200,200,"Hello MetaFile");
	meta.MoveTo(200,200);
	meta.LineTo(400,200);
	//3 关闭
	m_hMetaFile=meta.Close();
	//4 使用CMetaFile
	CClientDC dc(this);
	dc.PlayMetaFile(m_hMetaFile);
}
Example #4
0
void CGelView::OnEditCopy() 
{

	if ( !OpenClipboard() ) {
		AfxMessageBox("Cannot Open Clipboard", MB_OK | MB_ICONEXCLAMATION);
		return;
	}
	
	
	if ( !EmptyClipboard() ) {
		AfxMessageBox("Cannot Empty Clipboard", MB_OK | MB_ICONEXCLAMATION);
		return;
	}

	CGenedocDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	CMetaFileDC dcMeta;

	dcMeta.Create();

	CDC* pDC = GetDC();


	double ypi = pDC->GetDeviceCaps(LOGPIXELSY);
	double xpi = pDC->GetDeviceCaps(LOGPIXELSX);

	int x = (int)((double)GetGelSize().cx/100.0 * xpi);
	int y = (int)((double)GetGelSize().cy/100.0 * ypi);

	CSize tSize(x,y);
	pDC->DPtoHIMETRIC(&tSize);

	dcMeta.SetAttribDC( pDC->m_hAttribDC );

	OnPrepareDC( &dcMeta );

	DrawGel( &dcMeta, CRect( 0, 0, tSize.cx, tSize.cy ) );

	HGLOBAL hMF = GlobalAlloc( GMEM_DDESHARE | GMEM_ZEROINIT | GMEM_MOVEABLE , sizeof(METAFILEPICT) );

	METAFILEPICT *pMFP = (METAFILEPICT *)GlobalLock( hMF );

	pMFP->mm = MM_ANISOTROPIC;
	pMFP->xExt = tSize.cx;
	pMFP->yExt = tSize.cy;

	HMETAFILE hMeta = dcMeta.Close();

	pMFP->hMF = hMeta;

	GlobalUnlock( hMF );

	if ( SetClipboardData(CF_METAFILEPICT, hMF) == NULL ) {
		AfxMessageBox( "Select Failed in SetClipBoardData", MB_OK | MB_ICONEXCLAMATION );
	}

// CBitmap
//
	if ( !CloseClipboard() ) {
		AfxMessageBox( "CloseClipboard Failed", MB_OK | MB_ICONEXCLAMATION );
	}

	ReleaseDC( pDC );	// Moved this down here, needs testing.

	return;

}
Example #5
0
BOOL COleServerItem::GetMetafileData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium)
{
	ASSERT_VALID(this);
	ASSERT(AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE));
	ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));
	ASSERT(lpStgMedium->tymed == TYMED_NULL);   // GetDataHere not valid
	ASSERT(lpStgMedium->pUnkForRelease == NULL);

	// medium must be TYMED_MFPICT -- cannot fill in existing HGLOBAL
	if (!(lpFormatEtc->tymed & TYMED_MFPICT) || lpStgMedium->hGlobal != NULL)
		return FALSE;

	// create appropriate memory metafile DC
	CMetaFileDC dc;
	if (!dc.Create())
		return FALSE;

	// create attribute DC according to lpFormatEtc->ptd
	HDC hAttribDC = _AfxOleCreateDC(lpFormatEtc->ptd);
	if (hAttribDC == NULL)
		return FALSE;
	dc.SetAttribDC(hAttribDC);

	// Paint directly into the metafile.
	CSize size(0, 0);
	BOOL bResult = OnDrawEx(&dc, (DVASPECT)lpFormatEtc->dwAspect, size);

	// attribute DC is no longer necessary
	dc.SetAttribDC(NULL);
	::DeleteDC(hAttribDC);

	if (!bResult)
	{
#ifdef _DEBUG
		if (afxTraceFlags & traceOle)
			TRACE0("calling COleServerItem::OnDrawEx()failed.\n");
#endif
		return FALSE;
	}

	HMETAFILE hMF = dc.Close();
	if (hMF == NULL)
		return FALSE;

	HGLOBAL hPict;
	if ((hPict =
		::GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, sizeof(METAFILEPICT))) == NULL)
	{
		DeleteMetaFile(hMF);
		return FALSE;
	}
	LPMETAFILEPICT lpPict;
	if ((lpPict = (LPMETAFILEPICT)::GlobalLock(hPict)) == NULL)
	{
		DeleteMetaFile(hMF);
		::GlobalFree(hPict);
		return FALSE;
	}

	// set the metafile size
	lpPict->mm = MM_ANISOTROPIC;
	lpPict->hMF = hMF;
	if (size.cx == 0 && size.cy == 0 &&
		!OnGetExtent((DVASPECT)lpFormatEtc->dwAspect, size))
	{
		TRACE0("Warning: OnGetExtent failed during OnDrawEx --\n");
		TRACE0("\tpresentation metafile may be badly formed!\n");
	}
	lpPict->xExt = size.cx;
	lpPict->yExt = size.cy;  // HIMETRIC height
	if (lpPict->yExt < 0)
	{
		TRACE0("Warning: HIMETRIC natural size is negative.\n");
		lpPict->yExt = -lpPict->yExt;   // backward compatibility fix
	}

#ifdef _DEBUG
	if (lpPict->xExt == 0 || lpPict->yExt == 0)
	{
		// usually the natural extent is set to something interesting
		TRACE0("Warning: COleServerItem has no natural size --\n");
		TRACE0("\twill not work with some apps like MS Write.\n");
	}
#endif

	// return the medium with the hGlobal to the METAFILEPICT
	::GlobalUnlock(hPict);
	lpStgMedium->hGlobal = hPict;
	lpStgMedium->tymed = TYMED_MFPICT;
	return TRUE;
}