HanDs
NO.2

[Delphi文章] 截取被遮挡的Window画面 





学习中请遵循国家相关法律法规,黑客不作恶。没有网络安全就没有国家安全

本站需要登陆后才能查看

只要不是最小化的窗口,无论它被遮挡一部分还是全部,无论它的位置是否超出屏幕边界,都可以抓到

下面是代码:


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;


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
截取 遮挡 W in do w 画面
#1楼
发帖时间:2016-7-9   |   查看数:0   |   回复数:0
游客组