CImage(MFC) 加载剪贴板图像数据

CView *cv=this;
CImage* m_image;
OpenClipboard(NULL);
HANDLE h=::GetClipboardData(CF_BITMAP);   
if(h==0)
{
CloseClipboard(); 
return;
}
BITMAP bm;   
    GetObject(h,sizeof(bm),&bm);  
if(m_image!=NULL)
{
delete m_image;
m_image=NULL;

m_image=new CImage();
m_image->Create(bm.bmWidth,bm.bmHeight,32,0);
HDC hdc=m_image->GetDC();
CDC imgDC;
imgDC.Attach(hdc);
CBitmap *pBmp=new CBitmap;   
pBmp->Attach(h);   
CClientDC dc(cv);    
CDC memDC;   
memDC.CreateCompatibleDC(&dc);    
CBitmap *pOldBitmap=memDC.SelectObject(pBmp);  
imgDC.BitBlt(0,0,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);  
memDC.SelectObject(pOldBitmap);   
pBmp->Detach();
delete pBmp;   
imgDC.Detach();
m_image->ReleaseDC();


你可能感兴趣的:(mfc,剪贴板,CImage)