Advertisement
Guest User

MikelSV

a guest
Oct 23rd, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1.     int Grab(HWND hwnd){
  2.         if(!hwnd) return 0;
  3.         UGLOCK(*this);
  4.  
  5.         MRect rc; GetWindowRect(hwnd, rc);
  6.         HDC dc = GetWindowDC(hwnd);
  7.         if(!dc) return 0;      
  8.  
  9.         // Create compatible DC
  10.         HDC cdc = CreateCompatibleDC(dc);
  11.  
  12.         // Create a compatible bitmap
  13.         HBITMAP bmp = CreateCompatibleBitmap(dc, rc.GetW(), rc.GetH());
  14.  
  15.         // Select Bitmap
  16.         SelectObject(cdc, bmp);
  17.  
  18.         // Copy pixels from screen to the BITMAP
  19.         if(!BitBlt(cdc, 0, 0, rc.GetW(), rc.GetH(), dc, 0, 0, SRCCOPY)) return 0;
  20.  
  21.         int ret=NewHImage(bmp);    
  22.  
  23.         DeleteObject (bmp);
  24.         // Delete the hBitmapdc as you no longer need it
  25.         DeleteDC(cdc);
  26.         // Release the desktop device context handle
  27.         ReleaseDC(hwnd, dc);
  28.         return ret;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement