VC下截取当前屏幕的函数(Function of copy screen)
MFC中就有截取屏幕的相关函数:
ScrDC.CreateDC(“DISPLAY”, NULL, NULL, NULL);
具体函数如下:
//存储背景图片(成员变量) CBitmap* m_pBackBitmap; /******************************* * 拷贝屏幕固定区域 * 参数: * xStartPt - 拷贝屏幕的起始点X坐标 * yStartPt - 拷贝屏幕的起始点Y坐标 * width - 拷贝宽度 * height - 拷贝高度 * xToCopy - 拷贝目的地的起始点X坐标 * yToCopy - 拷贝目的地的起始点Y坐标 *******************************/ void CMyFun::CopyScreenToBitmap(xStartPt, yStartPt, width, height, xToCopy, yToCopy) { //NEW资源(调用一次重新拷贝一次) if (m_pBackBitmap != NULL) { delete m_pBackBitmap; m_pBackBitmap = NULL; } m_pBackBitmap = new CBitmap(); CDC ScrDC,MemDC; ScrDC.CreateDC("DISPLAY", NULL, NULL, NULL); MemDC.CreateCompatibleDC(&ScrDC); m_pBackBitmap->CreateCompatibleBitmap(&ScrDC,width,height); MemDC.SelectObject(m_pBackBitmap); //开始拷贝 MemDC.BitBlt(xStartPt, yStartPt, width, height,&ScrDC,xToCopy,yToCopy,SRCCOPY); ScrDC.DeleteDC(); MemDC.DeleteDC(); }
调用函数,实现截取全屏:
//取的屏幕分辨率 int width = ::GetSystemMetrics(SM_CXSCREEN); int height = ::GetSystemMetrics(SM_CYSCREEN); this->CopyScreenToBitmap(0,0,width,height,0,0); //这时m_pBackBitmap指向的CBitmap对象就存着全屏的图象了
Trackback from your site.