Jump to content
PeterPanettone

Menu boundaries from MenuHandle?

Recommended Posts

By using MSAA (Microsoft Active Accessibility), I can get the MenuHandle of a menu when the menu is displayed.

 

How can I get the boundaries of the displayed menu from the MenuHandle?

Edited by PeterPanettone

Share this post


Link to post
7 hours ago, PeterPanettone said:

How can I get the boundaries of the displayed menu from the MenuHandle?

You can't, as there is no way to get from the MenuHandle/HMENU to its dialog window.

 

However, there can only be 1 menu active at a time, so you should be able to use FindWindow/Ex() to find the HWND of the active menu whose window class name is "#32768"/MAKEINTATOM(0x8000),

 

Once you have the menu's HWND, you should be able to use GetWindowRect() to get its position and size.

Edited by Remy Lebeau
  • Thanks 1

Share this post


Link to post
On 2/26/2024 at 2:32 AM, Remy Lebeau said:

However, there can only be 1 menu active at a time, so you should be able to use FindWindow/Ex() to find the HWND of the active menu whose window class name is "#32768"/MAKEINTATOM(0x8000),

 

Once you have the menu's HWND, you should be able to use GetWindowRect() to get its position and size.

Thank you very much; I am now able to find the menu rectangle:

function PAGetDisplayedMenuRectangle: TRect;
var
  MenuWnd: HWND;
begin
  // Initialize the result rectangle to zero
  FillChar(Result, SizeOf(Result), 0);

  // Find the window handle of the active menu
  MenuWnd := FindWindowEx(0, 0, MAKEINTATOM($8000), nil);
  if MenuWnd <> 0 then
  begin
    // If the menu window is found, get its rectangle
    if not GetWindowRect(MenuWnd, Result) then
    begin
      // If GetWindowRect fails, reset the result to zero
      FillChar(Result, SizeOf(Result), 0);
    end;
  end;
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×