Guest User

Untitled

a guest
Mar 10th, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. int SaveBMPFile(char *filename, HBITMAP bitmap, HDC bitmapDC, int width, int height);
  4.  
  5. int ScreenCapture(int x, int y, int width, int height, char *filename){
  6. // get a DC compat. w/ the screen
  7. HDC hDc = CreateCompatibleDC(0);
  8.  
  9. // make a bmp in memory to store the capture in
  10. HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height);
  11.  
  12. // join em up
  13. SelectObject(hDc, hBmp);
  14.  
  15. // copy from the screen to my bitmap
  16. BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY);
  17.  
  18. // save my bitmap
  19. int ret = SaveBMPFile(filename, hBmp, hDc, width, height);
  20.  
  21. // free the bitmap memory
  22. DeleteObject(hBmp);
  23.  
  24. return ret;
  25. }
  26.  
  27. main(){
  28. ScreenCapture(500, 200, 300, 300, "testScreenCap.bmp");
  29. system("pause");
  30. }
Advertisement
Add Comment
Please, Sign In to add comment