知道窗口的句柄,怎样获得它的图象(Canvas),不能被其它窗口覆盖的? ( 积分: 100 )

  • 主题发起人 主题发起人 大伟001
  • 开始时间 开始时间

大伟001

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Timer1Timer(Sender: TObject);
var
cursorpoint: TagPOINT;
windowhandle: hwnd;
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
if GetCursorPos(cursorpoint) then
begin
windowhandle := windowfrompoint(cursorpoint);
Bitmap.Canvas.handle := GetDC(windowhandle); //得到图象是被覆盖的;
form1.Canvas.FillRect(form1.Canvas.ClipRect);
form1.Canvas.CopyRect(Rect(0, 0, 1000, 1000), Bitmap.Canvas, Rect(0, 0, 1000, 1000));
end;
end;
 
procedure TForm1.Timer1Timer(Sender: TObject);
var
cursorpoint: TagPOINT;
windowhandle: hwnd;
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
if GetCursorPos(cursorpoint) then
begin
windowhandle := windowfrompoint(cursorpoint);
Bitmap.Canvas.handle := GetDC(windowhandle); //得到图象是被覆盖的;
form1.Canvas.FillRect(form1.Canvas.ClipRect);
form1.Canvas.CopyRect(Rect(0, 0, 1000, 1000), Bitmap.Canvas, Rect(0, 0, 1000, 1000));
end;
end;
 
要得到图象不是被覆盖的
必须得到最上面的窗口的句柄,
windowfrompoint(cursorpoint);
这个API是不行的,必须递归调用.FindWindow(),GetWindow两个API得到最上层的子窗口才行
 
我知道用GetFormImage可以获取一个窗口的原始图象,但是必须是自己的程序中,如下:
Bitmap:= from2.GetFormImage;
我用以下方法,但是编译不能通过:
Bitmap:= (windowhandle as TForm).GetFormImage;
查过很多资料没有结果?
 
一个比较土的办法是,在COPYRECT之前,调用BringWindowToTop把窗口弄到最前面。
 
GetDcEx可以解决
 
var
windowhandle:thandle;
cu:tpoint;
Bitmap:TBitmap;
begin
GetCursorPOs(cu);
windowhandle := windowfrompoint(cu);
memo1.Lines.Add(inttostr(windowhandle));
if windowhandle<>0 then
begin
bitmap := Tbitmap.Create;
Bitmap.Canvas.handle := GetDC(windowhandle); //得到图象是被覆盖的;
Canvas.FillRect(Canvas.ClipRect);
Canvas.CopyRect(Rect(0, 0, 1000, 1000), Bitmap.Canvas, Rect(0, 0, 1000, 1000));
bitmap.Free;
end;
我用上面的代码,可以得当鼠标下面窗口的图像,如果你不像被覆盖,你要将Canvas改为TImage.Canvas,因为Form为刷新到刚才画的图像的
 
后退
顶部