by Richard Russell, December 2008
There may be circumstances when you need to detect whether a drop-down ('popup') menu is 'open', that is the menu selections are displayed. A particular example is when you have changed the mouse pointer (cursor) shape using MOUSE ON, in which case you may want to change it back to the normal pointer shape whilst the menu is displayed.
You can fairly easily achieve that by intercepting the WM_MENUSELECT message, which you can do using *SYS 1 and ON SYS. Typically you will need to use code similar to the following during the initialisation phase of your program:
WM_COMMAND = &111 WM_MENUSELECT = &11F MenuOpen% = FALSE Click% = 0 *SYS 1 ON SYS PROCsys(@msg%,@wparam%,@lparam%) : RETURN
The PROCsys routine (which should be placed out of harm's way, for example after your program's END statement) should look something like this:
DEF PROCsys(M%,W%,L%) CASE M% OF WHEN WM_COMMAND: Click% = W% AND &FFFF WHEN WM_MENUSELECT: MenuOpen% = (L%<>0) ENDCASE ENDPROC
This code sets the global variable MenuOpen% to TRUE whilst a menu is displayed and to FALSE when no menu is displayed. You could 'poll' it in your main program's loop to determine, for example, what mouse pointer shape to use.
Of course, if you prefer not to poll a global variable but to take action immediately on receipt of the WM_MENUSELECT message you can replace the code as required. Take care to note the precautions discussed here.
The code executed on receipt of the WM_COMMAND message is purely illustrative; in this case it sets the global variable Click% when a menu selection or button-press takes place. You should replace it with whatever code is appropriate for your application.