开发者

How can I capture screen under my own window excluding my own window

开发者 https://www.devze.com 2023-03-16 03:54 出处:网络
Assuming I would like to program a magnifier, how could I capture the content of the screen excluding my very own window ?

Assuming I would like to program a magnifier, how could I capture the content of the screen excluding my very own window ? I know how to capture the screen with my own window using BitBlt and the Desktop DC.

And to make it clearer: I want to show the magnified content in my window.

Edit: It seems that there is no other solution than 开发者_如何转开发to hide my window (or the client area) one way or another before I can capture the screen content under my window. Apparently this causes my window to flicker which renders this scenario pretty useless.


During the capture process set the forms AlphaBlend property to true and the AlphaBlendValue to 0. Be aware that this will make your form completely invisible.


You use PrintWindow() for that, but it is not fast and does not work for all applications.


You need to capture the screenshot from the DC of the desktop, into a bitmap in memory.

procedure CaptureScreenShot(acapture: TBitMap);
 var c: TCanvas;
     r: TRect;
 begin
  c:= TCanvas.Create;
  c.Handle:= GetWindowDC (GetDesktopWindow);
  try
    r:= Rect(0,0,screen.width,screen.height);
    acapture.Width:=screen.Width;
    acapture.Height:=screen.Height;
    acapture.Canvas.CopyRect(r, c, r);
  finally
    ReleaseDC(0, c.handle);
    c.Free;
  end;
end;

Add to this Uwe's answer to make your form invisible and you have....

FCapturedScreenShot:TBitmap;
....
FCapturedScreenShot:=TBitmap.Create;
....
AlphaBlend:=true;
AlphaBlendValue:=0; 
CaptureScreenshot(FCapturedScreenShot);
AlphaBlendValue:=False; 

use the captured screenshot for whatever you need, you might assign it over a bitmap in another form, or save it in an array of captured screens...


Try to minimize or hide you form before capture the screen and restore or show the form after capture screen

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号