ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Demo project: Capture Control (CaptureFromScreen with iecsSpecifiedWindow)
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

859 Posts

Posted - Jul 25 2021 :  03:47:20  Show Profile  Reply
This demo project captures the control (window) under the mouse cursor of any window, for example:



attach/PeterPanino/202172534320_CaptureControlTest.zip
21.24 KB

This works very well - except with the CLIENT AREA OF WINDOWS NOTEPAD!

Why this does not work with the CLIENT AREA OF WINDOWS NOTEPAD? The rectangle coordinates of the CLIENT AREA OF WINDOWS NOTEPAD and its handle are reported correctly. Is this a bug in the CaptureFromScreen function?

PeterPanino

859 Posts

Posted - Jul 25 2021 :  04:51:22  Show Profile  Reply
It seems that iecsSpecifiedWindow for some reason does not work with the CLIENT AREA OF WINDOWS NOTEPAD. So I created this workaround to automatically use iecsSpecifiedWindow2 if iecsSpecifiedWindow does not get the capture:

...
private
  { Private declarations } 
  ...   
  FCurrentHash: AnsiString;
  FOldHash: AnsiString;
  ...

GetCursorPos(FPoint);
if PTInRect(Self.BoundsRect, FPoint) then EXIT; // do not capture this window

FHandleOfWindowAtMousePos := Winapi.Windows.WindowFromPoint(FPoint); // Handle of Control under the mouse cursor
if FHandleOfWindowAtMousePos = FOldHandle then EXIT; // block the same handle as before
//CodeSite.Send('TForm1.Timer1Timer: FHandleOfWindowAtMousePos', FHandleOfWindowAtMousePos);
FOldHandle := FHandleOfWindowAtMousePos;

ImageEnView1.IO.CaptureFromScreen(iecsSpecifiedWindow, -1, FHandleOfWindowAtMousePos);
FCurrentHash := ImageEnView1.IEBitmap.GetHash();
if FCurrentHash = FOldHash then // if current bitmap is the same as before
begin
  ImageEnView1.IO.CaptureFromScreen(iecsSpecifiedWindow2, -1, FHandleOfWindowAtMousePos); // alternative capture method
  //CodeSite.Send('TForm1.Timer1Timer: alternative capture method');
end;
FOldHash := ImageEnView1.IEBitmap.GetHash();

ImageEnView1.Update;


Is this correct?
Go to Top of Page

PeterPanino

859 Posts

Posted - Jul 25 2021 :  08:35:09  Show Profile  Reply
Other incompatible windows are Visual Studio Code, TechSmith Snagit Editor. Why are they incompatible with CaptureFromScreen?
Go to Top of Page

xequte

38175 Posts

Posted - Jul 26 2021 :  01:30:47  Show Profile  Reply
Hi Peter

iecsSpecifiedWindow2 is available for apps that resist a standard screen capture. You should check the boolean result of CaptureFromScreen, and if it is false fall back to CaptureFromScreen2:

procedure TForm1.Timer1Timer(Sender: TObject);
var
  pt: TPoint;
  h: HWND;
begin
  GetCursorPos( pt );
  if PtInRect( Self.BoundsRect, pt ) then
    exit; // Over own window

  h := Winapi.Windows.WindowFromPoint( pt ); // Handle of control under the mouse cursor
  if ImageEnView1.IO.CaptureFromScreen( iecsSpecifiedWindow, -1, h ) = False then
    ImageEnView1.IO.CaptureFromScreen( iecsSpecifiedWindow2, -1, h );
end;



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

859 Posts

Posted - Jul 26 2021 :  07:19:12  Show Profile  Reply
What is the technical reason for certain apps resisting a standard screen capture with CaptureFromScreen?
Go to Top of Page

xequte

38175 Posts

Posted - Jul 26 2021 :  16:56:16  Show Profile  Reply
Hi Peter

Please google "PrintWindow Fails" for more detail.

In the upcoming release we fall back to a legacy method.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

859 Posts

Posted - Jul 30 2021 :  10:40:41  Show Profile  Reply
Hi Nigel

Thanks for the information.

When will the upcoming release be available?
Go to Top of Page

xequte

38175 Posts

Posted - Jul 30 2021 :  15:19:40  Show Profile  Reply
Hi Peter

Next week.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: