User Tools

Site Tools


detecting_20when_20a_20menu_20is_20open

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
detecting_20when_20a_20menu_20is_20open [2018/03/31 13:19] – external edit 127.0.0.1detecting_20when_20a_20menu_20is_20open [2024/01/05 00:22] (current) – external edit 127.0.0.1
Line 1: Line 1:
 =====Detecting when a menu is open===== =====Detecting when a menu is open=====
  
-//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 [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#mouseon|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 [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin8.html#starsys|*SYS 1]] and [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#onsys|ON SYS]]. Typically you will need to use code similar to the following during the initialisation phase of your program:\\ \\ +//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 [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#mouseon|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 [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin8.html#starsys|*SYS 1]] and [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#onsys|ON SYS]]. Typically you will need to use code similar to the following during the initialisation phase of your program: 
 + 
 +<code bb4w> 
         WM_COMMAND = &111         WM_COMMAND = &111
         WM_MENUSELECT = &11F         WM_MENUSELECT = &11F
Line 8: Line 10:
         *SYS 1         *SYS 1
         ON SYS PROCsys(@msg%,@wparam%,@lparam%) : RETURN         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:\\ \\ +</code> 
 + 
 +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: 
 + 
 +<code bb4w>
          DEF PROCsys(M%,W%,L%)          DEF PROCsys(M%,W%,L%)
          CASE M% OF          CASE M% OF
Line 15: Line 21:
          ENDCASE          ENDCASE
          ENDPROC          ENDPROC
 +</code>
 +
 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 [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#interrupts|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. 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 [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#interrupts|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.
detecting_20when_20a_20menu_20is_20open.1522502355.txt.gz · Last modified: 2024/01/05 00:18 (external edit)