000
25.02.2006, 19:23 Uhr
~Amazer0th
Gast
|
Hallo! Ich habe hier ein Programm aus mehreren zusammengeschnitten. Es sollte ein Screenshot machen und als BMP speichern, aber es funktioniert nicht.. könnt ihr mir helfen?
C++: |
/*screen capture example*/ #include <windows.h> #include <fstream> #include <stdio.h> #include <wingdi.h> #include <fstream.h>
#define SCREENWIDTH GetSystemMetrics(SM_CXSCREEN) #define SCREENHEIGHT GetSystemMetrics(SM_CYSCREEN)
HBITMAP g_hDeskBmp; HDC g_hMemDC; int g_nDCdata;
int main() { /*capture desktop and store for later use*/ HDC hdcDesk; hdcDesk=GetDC(HWND_DESKTOP); /*equivalent to hdcDesk=GetDC((HWND)0);*/ g_hMemDC=CreateCompatibleDC(0); g_hDeskBmp=CreateCompatibleBitmap(hdcDesk, SCREENWIDTH, SCREENHEIGHT); /*fill the bitmap with contents of desktop*/ g_nDCdata=SaveDC(g_hMemDC); SelectObject(g_hMemDC,g_hDeskBmp); BitBlt(g_hMemDC, 0, 0, SCREENWIDTH, SCREENHEIGHT,hdcDesk,0,0,SRCCOPY); //......................................................................................
// create the BMP file
// create output file ofstream bmpfile("d:\\filename.bmp"); // save bitmap file header BITMAPFILEHEADER fileHeader; fileHeader.bfType = 0x4d42; fileHeader.bfSize = 0; fileHeader.bfReserved1 = 0; fileHeader.bfReserved2 = 0; fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
if(!bmpfile.write((char*)&fileHeader, sizeof(fileHeader))) return 0;
// save bitmap info header BITMAPINFOHEADER infoHeader; infoHeader.biSize = sizeof(infoHeader); infoHeader.biWidth = 800; infoHeader.biHeight = 600; infoHeader.biPlanes = 1; infoHeader.biBitCount = 32; infoHeader.biCompression = BI_RGB; infoHeader.biSizeImage = 0; infoHeader.biXPelsPerMeter = 0; infoHeader.biYPelsPerMeter = 0; infoHeader.biClrUsed = 0; infoHeader.biClrImportant = 0;
if(!bmpfile.write((char*)&infoHeader, sizeof(infoHeader))) return 0;
// save color table (sample used here is 8-bit grayscale) if(infoHeader.biBitCount == 8) { RGBQUAD table[256]; for(size_t i = 0; i < 256; i++) table[i].rgbRed = table[i].rgbGreen = table[i].rgbBlue = (BYTE)i; if(!bmpfile.write((char*)table, 256*sizeof(RGBQUAD))) return 0; } else if(infoHeader.biBitCount == 4) { // 16 colors } else if(infoHeader.biBitCount == 1) { // only two colors (doesn't necessarily have to be always black and white!) }
// save bitmap data if(!bmpfile.write((char*)&hdcDesk, sizeof(hdcDesk))) return 0;
ReleaseDC(HWND_DESKTOP,hdcDesk); RestoreDC(g_hMemDC,g_nDCdata); DeleteDC(g_hMemDC); DeleteObject(g_hDeskBmp); // close the file return 0; //...................................................................................... }
|
Dieser Post wurde am 25.02.2006 um 20:07 Uhr von Pablo editiert. |