工控编程吧

标题: MFC如何把增强元文件复制到剪接板 [打印本页]

作者: qq263946146    时间: 2019-7-14 15:37
标题: MFC如何把增强元文件复制到剪接板
实现步骤如下:

(1) 如果工程还没有支持OLE,添加下面代码:
#include <afxole.h>

并在初始化中添加下面代码:
OleInitialize(NULL);


(2) 下面代码将视的位图放置到剪接板上:


void CMyView::OnEditCopyWmf()
{
        tagSTGMEDIUM * data;
        CClientDC dcRef( this );
        data = new tagSTGMEDIUM;
        CMetaFileDC * dcMeta;
        dcMeta = new CMetaFileDC();
        COleDataSource* pData = new COleDataSource;
        CRect lmbr;
        GetClientRect(lmbr);
        //replace "ImageName" with a description of this image
        dcMeta->CreateEnhanced(&dcRef, NULL, NULL,"ImageName\0Copy\0\0" );
        dcMeta->SetMapMode(MM_TEXT);
        //actually draw to the device context
        OnDraw(dcMeta);
        //done drawing
        data->tymed = TYMED_ENHMF;
        data->hEnhMetaFile = dcMeta->CloseEnhanced();
        pData->CacheData( CF_ENHMETAFILE, data );
        pData->SetClipboard();
        delete dcMeta;
        delete data;
}







欢迎光临 工控编程吧 (https://www.gkbc8.com/) Powered by Discuz! X3.4