void CScreenDlg::OnPaint()
{
CClientDC dc(this);
// 获取屏幕DC
HDC hScrDC = ::GetDC(NULL);
// 得到屏幕分辨率
INT nHeight = GetDeviceCaps(hScrDC, VERTRES);
INT nWidth = GetDeviceCaps(hScrDC, HORZRES);
// 创建屏幕DC的兼容DC
HDC hMemDC1 = CreateCompatibleDC(hScrDC);
// 创建屏幕兼容位图
HBITMAP hBitmap1 = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
// 把兼容位图选入兼容DC
HBITMAP hBitmap2 = (HBITMAP)SelectObject(hMemDC1, hBitmap1);
// 复制DC
BitBlt(hMemDC1, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY);
// 显示
BitBlt(dc.GetSafeHdc(), 0, 0, nHeight, nWidth, hMemDC1, 0, 0, SRCCOPY);
::DeleteObject(hBitmap1);
::DeleteDC(hMemDC1);
__super::OnPaint();
}
本文为“技术点滴”的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。