Captura de pantalla

Iniciado por ANTRAX, Mayo 22, 2011, 09:48:48 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Mayo 22, 2011, 09:48:48 PM Ultima modificación: Febrero 08, 2014, 06:08:22 PM por Expermicid
/*
CAPTURA PANTALLA
Programado por XpyXt
web: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
mail: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


Licencia de implementacion: publico este source bajo GPL, es decir, si tu
usas este codigo fuente en algun programa deberas publicar su source. Como
me entere de que lo has usado y no has publicado el codigo fuente voy a tu
casa y te amputo las manos. ¿Entendido?

Explicacion y modo de uso: Este source nos captura la pantalla del windows,
Hay 3 arrays de datos, 2 cabeceras del BMP y el RAW del bmp.


array CBA1 &bfh, Tamaño de la CBA1 sizeof(bfh)
array CBA2 &bmi.bmiHeader, Tamaño de la CBA2 sizeof(BITMAPINFOHEADER)
array (char *)pbBits, Tamaño del RAW bmi.bmiHeader.biSizeImage



Código: c
*/

//#define WINVER 0x501
//#define WINVER 0x400

#include <windows.h>
#include <stdio.h>
#include <wingdi.h>




void cap();
int main()
{
cap();
return 0;
}


void cap()
{

BITMAPINFO bmi;
BITMAPFILEHEADER bfh;


int nWidth;
int nHeight;

HWND hWnd;
HDC hdc ;
HDC memDC;
HBITMAP hbm ;
HBITMAP hbmOld;
BYTE *pbBits;


HANDLE hfile;
DWORD dwWritten;

nWidth = GetSystemMetrics(SM_CXSCREEN);
nHeight = GetSystemMetrics(SM_CYSCREEN);

hWnd = GetDesktopWindow();
hdc = GetDC(hWnd);
memDC = CreateCompatibleDC(hdc);
hbm = CreateCompatibleBitmap(hdc, nWidth, nHeight);
hbmOld = (HBITMAP)SelectObject(memDC, hbm);

BitBlt(memDC, 0, 0, nWidth, nHeight, hdc, 0, 0, SRCCOPY);



ZeroMemory(&bmi, sizeof(bmi));

bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = nWidth;
bmi.bmiHeader.biHeight = nHeight;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 32 * nWidth * nHeight / 8;


pbBits = (byte *) malloc(bmi.bmiHeader.biSizeImage); ;



GetDIBits( memDC,
hbm,
0,
bmi.bmiHeader.biHeight,
pbBits,
&bmi,
DIB_RGB_COLORS );





bfh.bfType = ('M' << 8) + 'B';
bfh.bfSize = sizeof(BITMAPFILEHEADER) +
bmi.bmiHeader.biSizeImage +
sizeof(BITMAPINFOHEADER);
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);



//(char *)pbBits // string de datos imagen sin cabezeras



// por si lo quieres guadar en el fichero.
hfile = CreateFile( ("c:\\screenXXX.bmp"),
GENERIC_WRITE,
0,
0,
OPEN_ALWAYS,
0,
0 );



WriteFile(hfile,&bfh, sizeof(bfh), &dwWritten, NULL);
WriteFile(hfile,&bmi.bmiHeader, sizeof(BITMAPINFOHEADER), &dwWritten, NULL);
WriteFile(hfile,pbBits, bmi.bmiHeader.biSizeImage, &dwWritten, NULL);


CloseHandle(hfile);


SelectObject(memDC, hbmOld);
DeleteDC(memDC);
ReleaseDC(hWnd,hdc);
DeleteObject(hbm);

free(pbBits);


}