怎么抓去被遮住的Window图像(200分)

  • 主题发起人 主题发起人 HN-Huang
  • 开始时间 开始时间
H

HN-Huang

Unregistered / Unconfirmed
GUEST, unregistred user!
当要抓取的window不是当前窗口,用一下代码,将没办法完成任务。
S:=EDit1.Text;
h:=findWindow(nil,Pchar(S));
DC:=GetWindowDC(h);
BCanvas:=TCanvas.Create;
BCanvas.Handle:=Dc;
Image1.Canvas.CopyRect(rect(0,0,100,200),BCanvas,rect(0,0,100,200))

抓到的是被遮住了的一部分。

怎么才能真正的抓到所需要的,难道真的一定要stay on top的窗口才能抓吗?
 
没见过可以抓不可见窗体的软件[:(]
 
真的没有办法的.
 
先激活它,再抓?
 
激活窗口不可接受,因为差不多每秒要抓2副图。太闪烁了吧
真的不行吗?
getwindowdc()到底什么意思。

那有滚动条的窗口怎么抓全的,谢谢,请继续关注。
 
滚动条?
 
先激活它,再抓?
有道理啊,抓完再改回来就行了。
 
不能抓不可视窗口
 
const
WS_EX_LAYERED = $00080000;
var
DC: HDC;
FStyle: Longint;
FCanvas: TCanvas;
bmpScreen : TBitmap;
begin
FStyle := GetWindowLong(FFadeWin.Handle, GWL_EXSTYLE);
FStyle := FStyle or WS_EX_LAYERED;
SetWindowLong(FFadeWin.Handle, GWL_EXSTYLE, FStyle);
Sleep(50);
bmpScreen := TBitmap.Create;
bmpScreen.Width := FFadeWin.Width;
bmpScreen.Height := FFadeWin.Height;
bmpScreen.Canvas.Lock;
DC := GetDC(0);
with bmpScreen do
Bitblt(Canvas.Handle, 0, 0,
FFadeWin.Width, FFadeWin.Height,
DC, FFadeWin.Left, FFadeWin.Top, SRCCOPY);
ReleaseDC(0, DC);
bmpScreen.Canvas.UnLock;

FStyle := GetWindowLong(FFadeWin.Handle, GWL_EXSTYLE);
FStyle := FStyle and (not WS_EX_LAYERED);
SetWindowLong(FFadeWin.Handle, GWL_EXSTYLE, FStyle);
end;
 
WS_EX_LAYERED

DC := GetDC(0);
 
还是不行。
当有部分窗体被遮住了,还要抓到下面的窗口
怎么办呢?
 
还是问比尔.该死大爷吧!
 
被遮住的部分,强制调用该窗口的PAINT事件,画到你的DC上来。
滚动条以外的部分画都没画,怎么截
 
如果是你自己的窗口,你可以用getformimage看看,别人的,俺不知道
 
做一个循环,列出所有存在的窗口,然后根据这些窗口的句柄捕获对应的窗口
 
function GetFormImageByHandle(Handle:THandle): TBitmap;
var
Ofs: Integer;
begin
Result := TBitmap.Create;
try
Result.Width := ClientWidth;
Result.Height := ClientHeight;
Result.Canvas.Brush := Brush;
Result.Canvas.FillRect(ClientRect);
Result.Canvas.Lock;
try
if GetWindowLong(Handle, GWL_STYLE) and WS_BORDER <> 0 then
Ofs := -1 // Don't draw form border
else
Ofs := 0; // There is no border
PaintTo(Result.Canvas.Handle, Ofs, Ofs);
finally
Result.Canvas.Unlock;
end;
except
Result.Free;
raise;
end;
end;
能使么,我记得以前好像能阿
 
function TForm1.GetFormImageByHandle1(Handle:THandle; Left, top, Width, Height: Integer): TBitmap;
var
Ofs: Integer;
CR: TRect;
begin
Result := TBitmap.Create;
try
Cr.TopLeft := Point(Left,Top);
Cr.BottomRight := Point(Left + Width,Top + Height);
Result.Width := Width;
Result.Height := Height;
Result.Canvas.Brush := Brush;
Result.Canvas.FillRect(Cr);
Result.Canvas.Lock;
try
if GetWindowLong(Handle, GWL_STYLE) and WS_BORDER <> 0 then
Ofs := -1 // Don't draw form border
else
Ofs := 0; // There is no border
PaintTo(Result.Canvas.Handle, -1*Left+Ofs, -1*Top+Ofs);
finally
Result.Canvas.Unlock;
end;
except
Result.Free;
raise;
end;
end;
 
后退
顶部