Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Cteni screenshotu. Dynamicky vytvori handles, pokud je jeste nemame.
- // Typy promennych - viz MSDN.
- //
- void get_screenshot()
- {
- // vyrez obrazu, ktery chceme cist
- int x = image_x; // offset
- int y = image_y;
- int cx = image_w; // sirka, vyska od offsetu
- int cy = image_h;
- // Retrieve the handle to a display device context for the client area of the window.
- if (!hdcScreen) hdcScreen = GetDC(NULL);
- // Create a compatible DC which is used in a BitBlt from the window DC
- if (!hdcMemDC) hdcMemDC = CreateCompatibleDC(hdcScreen);
- if(!hdcMemDC)
- {
- printf("!hdcMemDC\n");
- return;
- }
- // Create a compatible bitmap from the Window DC
- if (!hbmScreen) hbmScreen = CreateCompatibleBitmap(hdcScreen, cx, cy);
- if(!hbmScreen)
- {
- printf("!hbmScreen\n");
- return;
- }
- // Select the compatible bitmap into the compatible memory DC.
- SelectObject(hdcMemDC,hbmScreen);
- // Bit block transfer into our compatible memory DC.
- if(!BitBlt(hdcMemDC,
- 0,0,
- cx, cy,
- hdcScreen,
- x,y,
- SRCCOPY | CAPTUREBLT))
- {
- printf("BitBlt has failed\n");
- return;
- }
- // Get the BITMAP from the HBITMAP
- GetObject(hbmScreen,sizeof(BITMAP),&bmpScreen);
- // BITMAPFILEHEADER bmfHeader;
- BITMAPINFOHEADER bi;
- bi.biSize = sizeof(BITMAPINFOHEADER);
- bi.biWidth = bmpScreen.bmWidth;
- bi.biHeight = bmpScreen.bmHeight;
- bi.biPlanes = 1;
- bi.biBitCount = 32;
- bi.biCompression = BI_RGB;
- bi.biSizeImage = 0;
- bi.biXPelsPerMeter = 0;
- bi.biYPelsPerMeter = 0;
- bi.biClrUsed = 0;
- bi.biClrImportant = 0;
- DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;
- // alokace vnitrniho bufferu - ten pak vnitrne pouzivame
- if (!hDIB) hDIB = new unsigned char[dwBmpSize];
- // Zkopirovani do bufferu
- GetDIBits(hdcScreen, hbmScreen, 0,
- (UINT)bmpScreen.bmHeight,
- hDIB,//lpbitmap,
- (BITMAPINFO *)&bi, DIB_RGB_COLORS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement