Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way of handling a mouse drag?

Tags:

c++

windows

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?

like image 509
Mike Morum Avatar asked May 26 '11 16:05

Mike Morum


People also ask

How do you drag click properly?

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).

What is the drag function of a 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.


1 Answers

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.

like image 135
Mark Ransom Avatar answered Oct 25 '22 00:10

Mark Ransom