I need to implement mouse drag events which look something like this:
class MouseDragEvent
{
public:
uint m_btn;
uint m_x, m_y;
uint m_delta_x, m_delta_y;
};
I think I will need to check for WM_LBUTTONDOWN and WM_LBUTTONUP messages and manually find the change in x and y. Is there a drag message or a better way?
Position your index (left mouse button) and middle finger (right mouse button) over the upper edge of the mouse button. To drag click, simply flick your wrist slightly at an angle while gently pressing the mouse button in a downward direction (towards the front of the mouse).
Dragging the mouse refers to moving its position while holding the mouse button depressed. Dragging is used in the Plot window to move text items and to move the plot itself within the Plot window.
Start by detecting WM_LBUTTONDOWN
. Record the starting coordinates where the mouse button was pressed. Check for WM_MOUSEMOVE
, and when the mouse has moved outside the rectangle determined by GetSystemParameters(SM_CXDRAG)
and GetSystemParameters(SM_CYDRAG)
use SetCapture
to capture the mouse. At this point continue responding to WM_MOUSEMOVE
and check for WM_LBUTTONUP
. You might want to change the mouse cursor at this point. Also check for WM_CAPTURECHANGED
, which means the drag has been aborted. After the drag is complete call ReleaseCapture
.
Edit: Most of this process can be automated with the DragDetect
function. Call this function from the WM_LBUTTONDOWN handler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With