Taking a screenshot

I need some help with winapi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
HDC hScreenDC = CreateDC(L"DISPLAY", NULL, NULL, NULL);
HDC hMemoryDC = CreateCompatibleDC(hScreenDC);

int x = GetDeviceCaps(hScreenDC, HORZRES);
int y = GetDeviceCaps(hScreenDC, VERTRES);

HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, x, y);

HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemoryDC, hBitmap);      

BitBlt(hMemoryDC, 0, 0, x, y, hScreenDC, 0, 0, SRCCOPY);
hBitmap = (HBITMAP)SelectObject(hMemoryDC, hOldBitmap);               

DeleteDC(hMemoryDC);
DeleteDC(hScreenDC);


HDC hdc=CreateCompatibleDC(NULL);


BITMAPINFO bmi;
bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth=x;
bmi.bmiHeader.biHeight=y;
bmi.bmiHeader.biPlanes=1; 
bmi.bmiHeader.biBitCount=32;
bmi.bmiHeader.biCompression=BI_RGB;
bmi.bmiHeader.biSizeImage=0;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;

BYTE values[3*1280*200];

int lines=GetDIBits(hdc,hBitmap,1,200,values,&bmi,DIB_RGB_COLORS);

I'm trying to take a screenshot, and then get the rgb values for each pixel from the bitmap.

I copied the first part from http://stackoverflow.com/questions/3291167/how-to-make-screen-screenshot-with-win32-in-c and tried to somehow come up with the rest myself.. and as expected it didn't turn out as I had hoped.

Converting the values results in a mostly black picture with a few lines of randomly coloured pixels at the bottom.

Help would be appreciated ^
Last edited on
bump
Topic archived. No new replies allowed.