实现步骤如下:
(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; }