1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
| function CaptureScreen(percent:double;bitCount:integer;var x,y:integer):HBITMAP; var BmpInfo:BITMAPINFO; hWindow:hWnd; DC1,DC2:hDC; p:pointer; begin hWindow := GetDesktopWindow(); DC1 := GetDC(hWindow); x := GetDeviceCaps(DC1,HORZRES); y := GetDeviceCaps(DC1,VERTRES);
ZeroMemory(@BmpInfo.bmiHeader, sizeof(BITMAPINFOHEADER)); BmpInfo.bmiHeader.biWidth := round(x * percent); BmpInfo.bmiHeader.biHeight := round(y * percent); BmpInfo.bmiHeader.biPlanes := 1; BmpInfo.bmiHeader.biBitCount := bitCount; BmpInfo.bmiHeader.biSize := sizeof(BITMAPINFOHEADER); DC2 := CreateCompatibleDC(0); Result := CreateDIBSection(DC2,BmpInfo, DIB_RGB_COLORS,p, 0, 0); SelectObject(DC2, Result); if(percent <> 1)then begin SetStretchBltMode(DC2, HALFTONE); SetBrushOrgEx(DC2, 0, 0, nil); StretchBlt(DC2, 0, 0, BmpInfo.bmiHeader.biWidth, BmpInfo.bmiHeader.biHeight, DC1, 0, 0, x, y, SRCCOPY); end else BitBlt(DC2, 0, 0, BmpInfo.bmiHeader.biWidth, BmpInfo.bmiHeader.biHeight, DC1, 0, 0, SRCCOPY);
DeleteDC(DC2); ReleaseDC(hWindow, DC1); end; |