拷貝pWnd指向的視窗的指定地區到剪貼簿

來源:互聯網
上載者:User

 

//拷貝pWnd指向的視窗的lpSrcRect到剪貼簿//運行過此程式,可以開啟畫圖進行粘貼測試CopyScreenToClipboard(CWnd *pWnd, CRect *lpSrcRect){if(!IsWindow(pWnd->GetSafeHwnd())){AfxMessageBox("視窗控制代碼無效");return (FALSE);}// first, determine the update region and select itif ( ! pWnd->OpenClipboard() ){AfxMessageBox( "無法開啟剪貼簿" );return (FALSE);}// Remove the current Clipboard contentsif( ! EmptyClipboard() ){AfxMessageBox( "清空剪貼簿失敗" );return (FALSE);}//int   Width = lpSrcRect->Width();   int   Height = lpSrcRect->Height();CDC *pDC = pWnd->GetDC();//建立記憶體DCCDC memDC;memDC.CreateCompatibleDC(pDC);//建立位元影像CBitmap m_Bitmap;m_Bitmap.CreateCompatibleBitmap(pDC,Width,Height);//選中位元影像memDC.SelectObject(&m_Bitmap);//拷貝memDC.BitBlt(0, 0, Width, Height,pDC, 0, 0,SRCCOPY);//拷貝至剪貼簿SetClipboardData(CF_BITMAP,m_Bitmap.m_hObject);//關閉剪貼簿CloseClipboard();return (TRUE);}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.