工控编程吧

标题: MFC如何把位图放置到剪接板上 [打印本页]

作者: qq263946146    时间: 2019-7-14 15:35
标题: MFC如何把位图放置到剪接板上
实现步骤如下:

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

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


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

void CMyView::OnEditCopy()
{
       
        COLORREF BACKGROUND_COLOR = RGB(255,255,255);
        tagSTGMEDIUM * data;
        CBitmap * junk;
        COleDataSource* pData = new COleDataSource;
        data = new tagSTGMEDIUM;
        junk = new CBitmap();
        CClientDC cdc(this);
        CDC dc;
        dc.CreateCompatibleDC(&cdc);
        CRect client;
        //replace this with something that calculates
        //the proper rectangle size
        GetClientRect(client);
        junk->CreateCompatibleBitmap(&cdc,client.Width(),client.Height());
        dc.SelectObject(junk);
        CBrush fill(BACKGROUND_COLOR);
        dc.FillRect(client,&fill);
        //replace this with something that draws to a CDC
        OnDraw(&dc);
        data->tymed = TYMED_GDI;
        data->hBitmap = HBITMAP(*junk);
        pData->CacheData( CF_BITMAP, data );
        pData->SetClipboard();
        delete data;
        delete junk;
       
}







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