User Tools

Site Tools


responding_20to_20mouse_20double-clicks

Differences

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

Link to this comparison view

responding_20to_20mouse_20double-clicks [2018/03/31 13:19]
127.0.0.1 external edit
responding_20to_20mouse_20double-clicks [2018/04/16 14:31] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Responding to mouse double-clicks===== =====Responding to mouse double-clicks=====
  
-//by Richard Russell, October 2015//\\ \\  By default the [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​onmouse|ON MOUSE]] event interrupt is activated by clicking one of the mouse buttons, but a **double-click** is not distinguishable from a single click. If you specifically want to respond to mouse double-clicks two steps are necessary; firstly you must enable them as follows:\\ \\ +//by Richard Russell, October 2015//\\ \\  By default the [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​onmouse|ON MOUSE]] event interrupt is activated by clicking one of the mouse buttons, but a **double-click** is not distinguishable from a single click. If you specifically want to respond to mouse double-clicks two steps are necessary; firstly you must enable them as follows: 
 + 
 +<code bb4w>
         SYS "​GetClassLong",​ @hwnd%, GCL_STYLE TO wc%         SYS "​GetClassLong",​ @hwnd%, GCL_STYLE TO wc%
         SYS "​SetClassLong",​ @hwnd%, GCL_STYLE, wc% OR CS_DBLCLKS         SYS "​SetClassLong",​ @hwnd%, GCL_STYLE, wc% OR CS_DBLCLKS
-This code should be executed just once during the initialisation phase of your program (use the **Windows Constants utility** to add declarations for the GCL_STYLE and CS_DBLCLKS constants in the usual way).\\ \\  Secondly, you need to modify your ON MOUSE event handler to examine the **@msg%** system variable in order to discover whether the interrupt was caused by a single or double click. @msg% will have one of the following values:\\ +</​code>​ 
 + 
 +This code should be executed just once during the initialisation phase of your program (use the **Windows Constants utility** to add declarations for the GCL_STYLE and CS_DBLCLKS constants in the usual way).\\ \\  Secondly, you need to modify your ON MOUSE event handler to examine the **@msg%** system variable in order to discover whether the interrupt was caused by a single or double click. @msg% will have one of the following values:
  
 | WM_LBUTTONDOWN\\ | Left button click\\ | | WM_LBUTTONDOWN\\ | Left button click\\ |
Line 12: Line 16:
 | WM_MBUTTONDBLCLK\\ | Middle button double-click\\ | | WM_MBUTTONDBLCLK\\ | Middle button double-click\\ |
 | WM_RBUTTONDBLCLK\\ | Right button double-click\\ | | WM_RBUTTONDBLCLK\\ | Right button double-click\\ |
- There are various different approaches that may be adopted, but a simple asynchronous (polling) method is as follows:\\ \\ + 
 +There are various different approaches that may be adopted, but a simple asynchronous (polling) method is as follows: 
 + 
 +<code bb4w>
         REM. During initialisation:​         REM. During initialisation:​
         DIM Mouse%(2), mous%(2)         DIM Mouse%(2), mous%(2)
Line 20: Line 27:
         mous%() = 0         mous%() = 0
         SWAP mous%(), Mouse%()         SWAP mous%(), Mouse%()
-On receiving a mouse click **mous%(0)** will contain the **@msg%** value, **mous%(1)** will contain the **@wparam%** value (which contains information on whether the Shift and/or Control keys were pressed) and **mous%(2)** will contain the **@lparam%** value (which contains information on the position of the mouse when it was clicked). See the description of [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​onmouse|ON MOUSE]] in the main Help documentation for more details.\\ \\  If you prefer to use a synchronous method you can call a procedure when the interrupt occurs, as follows:\\ \\ +</​code>​ 
 + 
 +On receiving a mouse click **mous%(0)** will contain the **@msg%** value, **mous%(1)** will contain the **@wparam%** value (which contains information on whether the Shift and/or Control keys were pressed) and **mous%(2)** will contain the **@lparam%** value (which contains information on the position of the mouse when it was clicked). See the description of [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​onmouse|ON MOUSE]] in the main Help documentation for more details.\\ \\  If you prefer to use a synchronous method you can call a procedure when the interrupt occurs, as follows: 
 + 
 +<code bb4w>
         ON MOUSE PROCmouse(@msg%,​ @wparam%, @lparam%) : RETURN         ON MOUSE PROCmouse(@msg%,​ @wparam%, @lparam%) : RETURN
-\\  ​Note that when the user double-clicks the mouse you may well receive a '​single click' interrupt as well, and your program will need to cope with that.+</​code>​ 
 + 
 +Note that when the user double-clicks the mouse you may well receive a '​single click' interrupt as well, and your program will need to cope with that.
responding_20to_20mouse_20double-clicks.txt · Last modified: 2018/04/16 14:31 by richardrussell