PeterPanettone 157 Posted February 25 (edited) 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 February 25 by PeterPanettone Share this post Link to post
Remy Lebeau 1330 Posted February 26 (edited) 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 February 26 by Remy Lebeau 1 Share this post Link to post
PeterPanettone 157 Posted February 27 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