dt1
June 14, 2005, 7:15am
1
I would like to save the current screen to some kind of bitmapped file. I.e. I would like to save the contents of the file under .png or .gif or .jpg. I would like this process to be automated and quick. Are there any built in routines? Or do I have to use a third party component? I am running in Visual Studio .NET in c++ if that helps.
Thanks
libTIFF makes it pretty easy to write out TIFF files:
http://www.remotesensing.org:16080/libtiff/
If all you want is a screen capture:
#pragma once
#include <atlstr.h>
#include <atlimage.h>
bool ScreenCapture(string filename,HWND hWnd){
HDC hDC;
CImage img; //bitmap holder created
hDC = GetWindowDC(hWnd); //Now get it's DC handle
HDC hMemDC = CreateCompatibleDC(hDC);
RECT r;
GetWindowRect(hWnd,&r);
SIZE size;
size.cx = r.right-r.left;
size.cy = r.bottom-r.top;
//capture screen
HBITMAP hBitmap = CreateCompatibleBitmap(hDC, size.cx, size.cy);
if (hBitmap)
{
SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
ReleaseDC(NULL, hDC);
img.Attach(hBitmap);
img.Save(filename);
DeleteObject(hBitmap);
return true;
}
return false;
}
Filename is the name and location of the file. It can be .bmp or .jpg.
If you want more detail than a screen capture, you have to mess with the PIXELFORMATDESCRIPTOR and DIB sections.
system
Closed
October 19, 2021, 6:29pm
4
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.