One of the things we have wanted to do in Word is get an event just before a drop-down menu is displayed. Word has an event just before a RMB popup menu is displayed, but nothing for the main menu.
BTW - we need it for functionality like enabling/disabling the cut/copy menu items, they are enabled/disabled based on the selection state. But in our case, the code to determine if the menu item should be enabled/disabled is slow so we don't want to call it every time the caret moves.
The natural answer is to enable/disable the menu items just before they are displayed. But, easier said than done. Word draws it's own menus and generates its own events.
So I intercepted the Word message pump. Still not great. If you grab the message pump for the menu window, there are events that are generated after the menu is displayed. Calling menu.Enabled=true/false does no good. That just affects how the menu is displayed nest time.
Intercepting the OpusApp (main) window is better. You will get the WM_PARENTNOTIFY message from the left mouse click. But you get that message for a left mouse click anywhere. I added a hack that assumes the menu is at the top of the window. So if someone moves their window, this won't work.
As for bringing up the menu with keyboard accelerators, I couldn't find any way to see that before the menu was displayed. So for that you are SOL.
I am hoping that someone else will look at this and find a way to improve it. If so, please post a comment here!
The sample code is at http://www.windward.net/MyWordAddin.zip
Do you find this useful? If so please check out Windward Reports.
