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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Screenshot questions

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Feb 25 2023 : 11:38:49
I am trying to get screenshots of controls under the mouse pointer using ImageEnView1.IO.CaptureFromScreen:

procedure TForm1.TimerScreenshotTimer(Sender: TObject);
var
  pt: Winapi.Windows.TPoint;
  h, hc: Winapi.Windows.HWND;
  r: TRect;
  DC: HDC;
  GrandchildrenList: ^TWindowHandleList;
begin
  if not (GetKeyState(VK_CONTROL) < 0) then EXIT; // if not CTRL key is pressed then exit

  Winapi.Windows.GetCursorPos(pt); // get mousepointer position

  if Winapi.Windows.PtInRect(Self.BoundsRect, pt) then EXIT; // Exclude mouse over own window

  h := Winapi.Windows.WindowFromPoint(pt); // Handle of the WINDOW under the mouse pointer
  hc := Winapi.Windows.ChildWindowFromPoint(h, pt); // Handle of the WINDOW's child control

  // Iterate through all the control's children (if it has any):
  if GetKeyState(VK_SHIFT) < 0 then // if SHIFT key is pressed
  begin
    GrandchildrenCount := 0;
    EnumChildWindows(Hc, @CountGrandchildrenCallback, LPARAM(@GrandchildrenCount)); // wrong GrandchildrenCount
    CodeSite.Send('TForm1.TimerScreenshotTimer: GrandchildrenCount', GrandchildrenCount);
    // Question: How to iterate through ALL the control's children (if it has any) with the SHIFT key?
    // This only gets the control's FIRST child:
    if GetKeyState(VK_SHIFT) < 0 then // if SHIFT key is pressed
	    hc := Winapi.Windows.GetNextWindow(hc, GW_HWNDNEXT); // Get the first grandchild
  end;

  // Draw a red frame around the control:
  Winapi.Windows.GetWindowRect(hc, r);
  DC := GetWindowDC(0);
  try
    // Invalidate the previous control's rectangle:
    if prevHc <> 0 then
    begin
      Winapi.Windows.GetWindowRect(prevHc, prevR);      // get previous frame
      InvalidateRect(GetDesktopWindow(), @prevR, True); // remove previous frame: seems it does not work?
    end;

    // Draw the frame around the new control:
    FrameRect(DC, r, CreateSolidBrush(RGB(255, 0, 0)));
  finally
    ReleaseDC(0, DC);
  end;
  prevHc := hc;

  // Show the Control under the mouse pointer in the TImageEnView control:
  if hc <> 0 then
  begin
    if ImageEnView1.IO.CaptureFromScreen(iecsSpecifiedWindow, -1, hc) = False then
    begin
      ImageEnView1.IO.CaptureFromScreen(iecsSpecifiedWindow2, -1, hc);
    end;
  end;
end;


It works well, but there are some problems:

1. How can I iterate through the children of the control?

2. How can I reliably draw a red frame around the control?

3. How can I make a screenshot from a PopupMenu?

Please see the attached demo project:

attach/PeterPanino/2023225113826_TestScreenshotControlUnderMouse.zip
3.2 KB
3   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Feb 28 2023 : 19:27:19
Sorry, I don't use many third party components, so cannot give you good advice.

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Feb 28 2023 : 11:48:30
Actually, the ImageEn screenshot feature works very well, and I use it extensively in my app:



Also, the capturing of menus works perfectly.

The only part I'm having some issues with is the capturing of single controls and drawing a frame on them. Do you know any third-party component that can handle this?
xequte Posted - Feb 25 2023 : 15:51:47
Hi Peter

That functionality is not available with ImageEn's CaptureFromScreen() method. You are better to look for a specialist screen capturing component for that.

Nigel
Xequte Software
www.imageen.com