[Source] tirando screenshot da tela

Iniciado por Anonymous, 14 de Outubro , 2006, 07:38:04 PM

tópico anterior - próximo tópico

0 Membros e 1 Visitante estão vendo este tópico.

Anonymous

código roubado do trojan backoriffice 2000 :P)

Citarequipe evilcoderzBR

bom a imagem deve ser salva no c:\foto.jpg ;)


#include <windows.h>

void tirasnap(){
// Create device context
HDC hdc;
hdc=CreateDC("DISPLAY", NULL, NULL, NULL);

// Get dimensions
DWORD dwWidth, dwHeight, dwBPP, dwNumColors;

dwWidth = GetDeviceCaps(hdc, HORZRES);
dwHeight = GetDeviceCaps(hdc, VERTRES);
dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
if(dwBPP<=8) {
dwNumColors = GetDeviceCaps(hdc, NUMCOLORS);
dwNumColors = 256;
} else {
dwNumColors = 0;
}

// Create compatible DC
HDC hdc2;
hdc2=CreateCompatibleDC(hdc);

// Create bitmap
HBITMAP bitmap;
BITMAPINFO bmpinfo;
LPVOID pBits;

bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo.bmiHeader.biWidth = dwWidth;
bmpinfo.bmiHeader.biHeight = dwHeight;
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biBitCount = (WORD) dwBPP;
bmpinfo.bmiHeader.biCompression = BI_RGB;
bmpinfo.bmiHeader.biSizeImage = 0;
bmpinfo.bmiHeader.biXPelsPerMeter = 0;
bmpinfo.bmiHeader.biYPelsPerMeter = 0;
bmpinfo.bmiHeader.biClrUsed = dwNumColors;
bmpinfo.bmiHeader.biClrImportant = dwNumColors;

bitmap = CreateDIBSection(hdc, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0);
if(bitmap==NULL) {
DeleteDC(hdc);
DeleteDC(hdc2);
return;
}
HGDIOBJ gdiobj;
gdiobj = SelectObject(hdc2, (HGDIOBJ)bitmap);
if((gdiobj==NULL) || (gdiobj==(void *)GDI_ERROR)) {
DeleteDC(hdc);
DeleteDC(hdc2);
return;
}
if (!BitBlt(hdc2, 0,0, dwWidth, dwHeight, hdc, 0,0, SRCCOPY)) {
DeleteDC(hdc);
DeleteDC(hdc2);

return;
}

RGBQUAD colors[256];
if(dwNumColors!=0) {
dwNumColors = GetDIBColorTable(hdc2, 0, dwNumColors, colors);
}


// Fill in bitmap structures
BITMAPFILEHEADER bitmapfileheader;
BITMAPINFOHEADER bitmapinfoheader;

bitmapfileheader.bfType = 0x4D42;
bitmapfileheader.bfSize = ((dwWidth * dwHeight * dwBPP)/8) + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));
bitmapfileheader.bfReserved1 = 0;
bitmapfileheader.bfReserved2 = 0;
bitmapfileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));

bitmapinfoheader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfoheader.biWidth = dwWidth;
bitmapinfoheader.biHeight = dwHeight;
bitmapinfoheader.biPlanes = 1;
bitmapinfoheader.biBitCount = (WORD)dwBPP;
bitmapinfoheader.biCompression = BI_RGB;
bitmapinfoheader.biSizeImage = 0;
bitmapinfoheader.biXPelsPerMeter = 0;
bitmapinfoheader.biYPelsPerMeter = 0;
bitmapinfoheader.biClrUsed = dwNumColors;
bitmapinfoheader.biClrImportant = 0;

// Write bitmap to disk
HANDLE hfile;
DWORD dwBytes;

hfile=CreateFile("C:\\foto.jpg",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hfile==INVALID_HANDLE_VALUE) {
DeleteObject(bitmap);
DeleteDC(hdc2);
DeleteDC(hdc);

return;
}
WriteFile(hfile,&bitmapfileheader,sizeof(BITMAPFILEHEADER), &dwBytes, NULL);
WriteFile(hfile,&bitmapinfoheader,sizeof(BITMAPINFOHEADER), &dwBytes, NULL);
if(dwNumColors!=0)
WriteFile(hfile,colors,sizeof(RGBQUAD)*dwNumColors,&dwBytes,NULL);
WriteFile(hfile,pBits,(dwWidth*dwHeight*dwBPP)/8,&dwBytes,NULL);
CloseHandle(hfile);



// Clean up

DeleteObject(bitmap);
DeleteDC(hdc2);
DeleteDC(hdc);

return;
}


int main(){
    tirasnap();
}


bitcoder

Ei alguem sabe me dizer pq esse codigo compila certinho com o c++builder4 e quando eu compilo com o c++builder6 da erro ?

Se alguem souber o q tah de errado me avissa vai quebra um galo

valeu
programar ou ser programado

keenlanas

Cara, ele não cria um .jpg e sim um .bmp, tanto que o Printscreen fica com incriveis 3mb.

O certo é depois da rotina de criar um .bmp, criar outra que converta pra .jpg, mas isso é tenso de fazer no Dev-C++, só fica tranquilo de fazer no Visual C++, pq ele usa bibliotecas do windows pra fazer a conversão e tudo mais...

Bitcoder, procura o pacote SDK da Microsoft, nem todos os compiladores conseguem usar as bibliotecas do GDI+ (que eh o que se usa em windows pra criar e converter imagens, na maioria das vezes), então você tem que baxar e instalar o SDK e fazer seu compilador procurar os includes e as libs na pasta onde vc instalou ele...

Dá trabalho, cara, recomendo mto que você use simplesmente o Visual C++ e seja feliz XD