参考:http://blog.csdn.net/zhoujielunzhimi/article/details/8140887
http://blog.sina.com.cn/s/blog_55eccf2101009ojy.html
自动截取屏幕并进行保存
BOOL Screenshot(LPCTSTR lpszScreenFileName)
{
if (lpszScreenFileName == NULL
|| _tcslen(lpszScreenFileName) == 0)
{
return FALSE;
}
CDC *pDC;//屏幕DC
pDC = CDC::FromHandle(GetDC(NULL));//获取当前整个屏幕DC
int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);//获得颜色模式
int Width = pDC->GetDeviceCaps(HORZRES);
int Height = pDC->GetDeviceCaps(VERTRES);
CDC memDC;//内存DC
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
memBitmap.CreateCompatibleBitmap(pDC, Width, Height);
oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY);//复制屏幕图像到内存DC
//用CImage类对图片文件进行保存比较简单方便 CImage img;
img.Attach(memBitmap);
img.Save(lpszScreenFileName);
img.Detach();
memDC.SelectObject(oldmemBitmap);
return TRUE;
}