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: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
| procedure MakeScreenSnapShot(const dest: TBitmap; Flag: Byte= 0); var ScreenDC,CompDC: HDC; th: THandle; hBmp: HBitmap; WRect: TRect; w,h: Integer; begin Case Flag of 0: begin ScreenDC:= GetDC(0); w:= GetDeviceCaps(ScreenDC,HORZRES); h:= GetDeviceCaps(ScreenDC,VERTRES); end; 1: begin th:= GetForegroundWindow; GetWindowRect(th,WRect); w:= WRect.Right-WRect.Left; h:= WRect.Bottom-WRect.Top; ScreenDC:= GetWindowDC(th); end; 2: begin th:= GetForegroundWindow; GetClientRect(th,WRect); w:= WRect.Right-WRect.Left; h:= WRect.Bottom-WRect.Top; ScreenDC:= GetDC(th); end; else exit; end; CompDC:= CreateCompatibleDC(ScreenDC); hBmp:= CreateCompatibleBitmap(ScreenDC,w, h); th:= SelectObject(CompDC,hBmp); If Dest.PixelFormat<> pf24Bit then Dest.PixelFormat:= pf24bit; Dest.Width:= w; Dest.Height:= h; BitBlt(CompDC,0,0,Dest.Width,Dest.Height,ScreenDC,0,0,SRCCOPY); BitBlt(Dest.Canvas.Handle,0,0,Dest.Width,Dest.Height,CompDC,0,0,SRCCOPY);
DeleteObject(SelectObject(CompDC,th)); DeleteDC(CompDC); ReleaseDC(0,ScreenDC); DeleteDC(ScreenDC); end; |