Advertisement
Ai4rei

Code Style Comparison 2011 v. 2015

May 17th, 2015
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. // 2011
  2. void* GetScreenShot(void){
  3.     int width, height;
  4.     HDC hdcScreen, hdcCom;
  5.     HBITMAP hbmSnap;
  6.  
  7.     if((hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL))==NULL){
  8.         return NULL;
  9.     }
  10.     if((hdcCom = CreateCompatibleDC(hdcScreen))==NULL){
  11.         DeleteDC(hdcScreen);
  12.         return NULL;
  13.     }
  14.     width  = GetDeviceCaps(hdcScreen, HORZRES);
  15.     height = GetDeviceCaps(hdcScreen, VERTRES);
  16.     if((hbmSnap = CreateCompatibleBitmap(hdcScreen, width, height))==NULL){
  17.         DeleteDC(hdcCom);
  18.         DeleteDC(hdcScreen);
  19.         return NULL;
  20.     }
  21.     if(SelectObject(hdcCom, hbmSnap)==NULL
  22.     || !BitBlt(hdcCom, 0, 0, width, height, hdcScreen, 0, 0, SRCCOPY)){
  23.         DeleteObject(hbmSnap);
  24.         DeleteDC(hdcCom);
  25.         DeleteDC(hdcScreen);
  26.         return NULL;
  27.     }
  28.     DeleteDC(hdcCom);
  29.     DeleteDC(hdcScreen);
  30.     return hbmSnap;
  31. }
  32.  
  33. // 2015
  34. HBITMAP __WDECL CaptureScreenBitmap(void)
  35. {
  36.     bool bSuccess = false;
  37.     HBITMAP hBmp;
  38.     HDC hDC, hBmpDC;
  39.  
  40.     if((hDC = CreateDC("DISPLAY", NULL, NULL, NULL))!=NULL)
  41.     {
  42.         if((hBmpDC = CreateCompatibleDC(hDC))!=NULL)
  43.         {
  44.             SIZE Sz = { GetDeviceCaps(hDC, HORZRES), GetDeviceCaps(hDC, VERTRES) };
  45.  
  46.             if((hBmp = CreateCompatibleBitmap(hDC, Sz.cx, Sz.cy))!=NULL)
  47.             {
  48.                 HGDIOBJ hPrevBmp = SelectObject(hBmpDC, hBmp);
  49.  
  50.                 if(BitBlt(hBmpDC, 0, 0, Sz.cx, Sz.cy, hDC, 0, 0, SRCCOPY))
  51.                 {
  52.                     bSuccess = true;
  53.                 }
  54.  
  55.                 SelectObject(hBmpDC, hPrevBmp);
  56.  
  57.                 if(!bSuccess)
  58.                 {
  59.                     DeleteObject(hBmp);
  60.                     hBmp = NULL;
  61.                 }
  62.             }
  63.  
  64.             DeleteDC(hBmpDC);
  65.         }
  66.  
  67.         DeleteDC(hDC);
  68.     }
  69.  
  70.     return hBmp;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement