我在做一個MFC截圖,不知道代碼是否有錯,估計沒錯,現在的疑問是如果代碼沒錯的話,截完圖保存到剪切板了,然後到哪裡打開這個圖
void C截圖Dlg::GetScreenCapture()
{
//桌面窗口的設備上下文DC//畫布
HDC hDesktopDC = ::CreateDC(_T("DISPLAY"),NULL,NULL,NULL); //加::指出是API函數調用,不是成員函數調用
HDC hMemDC = ::CreateCompatibleDC(hDesktopDC);
//創建一個空白位圖
HBITMAP hBmp,hOldBmp;
int iWidth = abs(m_tEndpt.x-m_tBeginPt.x);
int iHeight = abs(m_tEndpt.y-m_tBeginPt.y);
hBmp = ::CreateCompatibleBitmap(hDesktopDC,iWidth,iHeight);
//把位圖放到內存DC
hOldBmp = (HBITMAP)::SelectObject(hMemDC,hBmp);
//把截圖區域拷貝到內存DC
POINT pt =m_tBeginPt;
ClientToScreen(&pt);//把窗口客戶區的相對坐標點轉化為桌面屏幕坐標點
//把選定的桌面區域拷貝到內存DC
::BitBlt(hMemDC,0,0,iWidth,iHeight,hDesktopDC,pt.x,pt.y,SRCCOPY);
//把舊的設備位圖設置回去
hBmp = (HBITMAP)SelectObject(hMemDC,hBmp);
//釋放
DeleteDC(hMemDC);
DeleteDC(hDesktopDC);
//把位圖保存到剪切板
if(OpenClipboard())//打開剪切板
{
EmptyClipboard();//清空剪切板
SetClipboardData(CF_BITMAP,hBmp);
CloseClipboard();
MessageBox(L"fsg");
}
DeleteObject(hBmp);
DeleteObject(hMemDC);
DeleteObject(hDesktopDC);
}
如果已經保存到了剪貼板,可以先粘貼到畫圖或者word中,然後再看嗎