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;


相关阅读 >>

Delphi 获取动态创建的image与scrollbox的相对位置

Delphi android实例-退出程序(xe8+小米2)

Delphi idhttp上传图给asp完美解决

Delphi 有授权许可的字符串拷贝函数源码

Delphi 实现dns上线域名解析(用于远控server)

Delphi 倒计时源码

dbgrideh 组件在borland开发工具中应用全攻略

Delphi如何计算一个文件目录的大小

Delphi xe5 android获取手机联系人,并用listview显示

Delphi 将memorystream保存到字符串

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...