只要不是最小化的窗口,无论它被遮挡一部分还是全部,无论它的位置是否超出屏幕边界,都可以抓到 下面是代码: function PrintWindow(Wnd: HWND; hDCBlt: HDC; nFlags: DWord): Bool; stdcall external 'user32.dll';
var Cap : string; procedure TForm1.Timer1Timer(Sender: TObject); var hBMP : HBITMAP; DC, DC1 : HDC; H : hWnd; R : TRect; begin H := FindWindow(nil, PAnsiChar(Cap)); if H > 0 then begin DC := GetWindowDC(H); GetWindowRect(H, R); hBMP := CreateCompatibleBitmap(DC, R.Right-R.Left, R.Bottom-R.Top); DC1 := CreateCompatibleDC(DC); SelectObject(DC1, hBMP); PrintWindow(H, DC1, 0); //image1.Canvas.Handle:=dc1; //image1.Refresh; Self.Image1.Height := Round((R.Bottom-R.Top) * (Self.Image1.Width / (R.Right-R.Left))); Self.Image1.Picture.Bitmap.Handle:= hBMP; Self.Image1.Refresh; DeleteDC(DC1); DeleteDC(DC); end; end; procedure TForm1.FormCreate(Sender: TObject); begin //Self.Image1.AutoSize := True; Self.Left := Screen.Width-Self.Width; Self.Top := Screen.Height-Self.Height-50; Self.FormStyle := fsStayOnTop; Self.Image1.Left := 2; Self.Image1.Top := 2; Self.Image1.Width := Self.Width - 100; Self.Image1.Stretch := True; Self.Timer1.Enabled := False; end; procedure TForm1.Button1Click(Sender: TObject); begin Cap := Self.Edit1.Text; Self.Timer1.Interval := 50; Self.Timer1.Enabled := True; end; |