Responding+to+mouse+double-clicks

//by Richard Russell, October 2015//

By default the [|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 format="bb4w" SYS "GetClassLong", @hwnd%, GCL_STYLE TO wc% SYS "SetClassLong", @hwnd%, GCL_STYLE, wc% OR CS_DBLCLKS 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: There are various different approaches that may be adopted, but a simple asynchronous (polling) method is as follows:
 * WM_LBUTTONDOWN || Left button click ||
 * WM_MBUTTONDOWN || Middle button click ||
 * WM_RBUTTONDOWN || Right button click ||
 * WM_LBUTTONDBLCLK || Left button double-click ||
 * WM_MBUTTONDBLCLK || Middle button double-click ||
 * WM_RBUTTONDBLCLK || Right button double-click ||

code format="bb4w" REM. During initialisation: DIM Mouse%(2), mous%(2) ON MOUSE Mouse% = @msg%, @wparam%, @lparam% : RETURN

REM. In your main 'polling loop': mous% = 0 SWAP mous%, Mouse% 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 [|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 format="bb4w" ON MOUSE PROCmouse(@msg%, @wparam%, @lparam%) : RETURN 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.