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
 CaptureFromScreen does not capture menu
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

914 Posts

Posted - Feb 25 2024 :  16:41:31  Show Profile  Reply
1. I start a Timer.

2. I focus the Notepad window.

3. I open a menu on Notepad.

4. Then the Timer fires and takes a screenshot from Notepad while the menu on Notepad is still open (ImageEnView1.IO.CaptureFromScreen(iecsSpecifiedWindow, -1, NotepadHandle).

5. The Notepad menu is not seen on the screenshot!

How to create a screenshot of the menu?

PeterPanino

914 Posts

Posted - Feb 26 2024 :  00:48:28  Show Profile  Reply
Is there no solution in ImageEn to capture a MENU? I've researched MSAA (Microsoft Active Accessibility), where I can get a MenuHandle notification right before Windows displays the menu. Then, I would have to obtain a screenshot of the whole screen with
IO.CaptureFromScreen(iecsScreen, -1 );
by using something like a Timer ...

Then I would have to compare the screens before and after the menu with Proc.Compare (which is extremely slow with large screens).

It would be nice if ImageEn had a built-in solution for creating a menu screenshot!
Go to Top of Page

xequte

38459 Posts

Posted - Feb 26 2024 :  03:14:22  Show Profile  Reply
Hi Peter

That's not possible with ImageEn, I'm afraid. I don't know of a screen capture component that supports it, but it should be possible.


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

PeterPanino

914 Posts

Posted - Feb 26 2024 :  15:21:28  Show Profile  Reply
Hi Nigel,

Could you provide a fallback screenshot method to capture menus, overlays, tooltips, etc., using BitBlt?
Go to Top of Page

PeterPanino

914 Posts

Posted - Feb 26 2024 :  15:48:17  Show Profile  Reply
I have tried this function using BitBlt:

function PACaptureWindowToTIEBitmap(AWinHandle: HWND): TIEBitmap;
var
  WindowDC: HDC;
  WindowRect: TRect;
  CaptureRect: TRect;
begin
  // Create the TIEBitmap that will hold the screenshot of the window
  Result := TIEBitmap.Create;

  // Get the device context (DC) of the window
  WindowDC := GetWindowDC(AWinHandle);
  try
    // Get the dimensions of the window, including non-client areas
    GetWindowRect(AWinHandle, WindowRect);
    CaptureRect := Rect(0, 0, WindowRect.Right - WindowRect.Left, WindowRect.Bottom - WindowRect.Top);

    // Prepare the TIEBitmap to match the window size
    Result.Allocate(CaptureRect.Right - CaptureRect.Left, CaptureRect.Bottom - CaptureRect.Top);

    // Copy from the window's DC to the TIEBitmap
    BitBlt(Result.Canvas.Handle, 0, 0, CaptureRect.Right, CaptureRect.Bottom, WindowDC, 0, 0, SRCCOPY);
  finally
    ReleaseDC(AWinHandle, WindowDC);
  end;
end;


But even that does not capture the menu!
Go to Top of Page

xequte

38459 Posts

Posted - Feb 26 2024 :  16:41:01  Show Profile  Reply
Hi

The hard part would be getting the handle of the menu. I think your best bet would be capturing the whole screen, then cropping it to the dimensions of the window you are trying to capture. Though that would still fail in situations where the menu is outside the area of the parent window.

However I am not particularly experienced in this area, you might want to ask on a more general forum, like Stack Overflow.

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

PeterPanino

914 Posts

Posted - Feb 27 2024 :  06:30:50  Show Profile  Reply
"The hard part would be getting the handle of the menu."

That is easy with MSAA (Microsoft Active Accessibility), although the handle itself is not needed to obtain the menu screenshot.

"I think your best bet would be capturing the whole screen, then cropping it to the dimensions of the window you are trying to capture."

That's exactly what I've done to solve the problem:



And then, by automatically making a TImageEnProc.CompareWith I extract the menu part of the image:



This will be available as a one-click solution (among many other ingenious solutions) in my upcoming Program Window Manager Pro 2.0.
Go to Top of Page

xequte

38459 Posts

Posted - Feb 27 2024 :  20:45:06  Show Profile  Reply
Nicely done

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

PeterPanino

914 Posts

Posted - Feb 28 2024 :  00:52:59  Show Profile  Reply
Now I've done it even better: I've created a method to take a screenshot of ANY menu even when it is displayed outside of a window. In this way, I can also make a screenshot of a CASCADED menu with submenus by combining the menu with its submenus by taking into account their relative positions and combining them into a common screenshot!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: