having handle to a menu (HMENU) is it possible to

2019-06-06 09:18发布

问题:

I know about the option for system menu, that is the alt+space one. And it's not pretty it involves looping all open windows through GetNextWindow. But I want to ask in more general way. That is having any menu handle, not necessarily to system menu (that is easy to find for any window) is it possible to get to its parent window ?

回答1:

In the particular case when hmenu obtained on the fly from an existing menu-window (class #32768): you can use GUITHREADINFO.hwndMenuOwner via GetGUIThreadInfo(GetWindowThreadProcessId). "On the fly" means: via SendMessageTimeout(MN_GETHMENU) or via GetMenuBarInfo(OBJID_CLIENT), after WindowFromPoint.



回答2:

No. Menus can be shared across windows, so there's no unique mapping from menus to windows.