Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Grab(HWND hwnd){
- if(!hwnd) return 0;
- UGLOCK(*this);
- MRect rc; GetWindowRect(hwnd, rc);
- HDC dc = GetWindowDC(hwnd);
- if(!dc) return 0;
- // Create compatible DC
- HDC cdc = CreateCompatibleDC(dc);
- // Create a compatible bitmap
- HBITMAP bmp = CreateCompatibleBitmap(dc, rc.GetW(), rc.GetH());
- // Select Bitmap
- SelectObject(cdc, bmp);
- // Copy pixels from screen to the BITMAP
- if(!BitBlt(cdc, 0, 0, rc.GetW(), rc.GetH(), dc, 0, 0, SRCCOPY)) return 0;
- int ret=NewHImage(bmp);
- DeleteObject (bmp);
- // Delete the hBitmapdc as you no longer need it
- DeleteDC(cdc);
- // Release the desktop device context handle
- ReleaseDC(hwnd, dc);
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement