Event when Menu is Opened - Is a Menu Dropped?

The recent discussion of knowing when a Combo is dropped reminded me of the question of getting an Event before the Menus open so they can be modified based on the current state.

There are Windows Messages for this so SV could setup Modal Events like a LIST Tree has Event:Expanding and Event:Contracting.

WM_ENTERMENULOOP                EQUATE(0211h)   !1st message,once, wParm=1 if TrackPopupMenu i.e. POPUP() http://msdn.microsoft.com/en-us/library/ms647595(VS.85).aspx
                                                !   The WM_ENTERMENULOOP message informs an application's main window procedure that a menu modal loop has been entered. 

WM_INITMENU                     EQUATE(0116h)   !next,once, passes wParam as hMenu to menubar   http://msdn.microsoft.com/en-us/library/ms646344(VS.85).aspx
                                                !   The WM_INITMENU message is sent when a menu is about to become active. It occurs when the user clicks an item on the menu bar or presses a menu key. This allows the application to modify the menu before it is displayed. 

WM_INITMENUPOPUP                EQUATE(0117h)   !next,each, passed hSubMenu to menu activated   http://msdn.microsoft.com/en-us/library/ms646347(VS.85).aspx

WM_EXITMENULOOP                 EQUATE(0212h)   !last message,once

I posted an example program here:

When the menu is opened the current time is placed in the first menu item and a counter as proof the menu was updated right when opened.

     ?Menu1Item1{PROP:Text}='Menu Opened ' & FORMAT(CLOCK(),@t4) |
                            &' - LT#'&  LongThread 
          LongThread + =1

The Sheet Menu is adjusted based on the currently selected tab:

 OF ?Tab1 ; Enable(?SheeMenuTab1)
 OF ?Tab2 ; Enable(?SheeMenuTab2)
 OF ?Tab3 ; Enable(?SheeMenuTab3)

The Sheet / Menu sync is just a simple example. I would code that in the Sheet’s Event:NewSelection.

1 Like