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?
Start by detecting
WM_LBUTTONDOWN. Record the starting coordinates where the mouse button was pressed. Check forWM_MOUSEMOVE, and when the mouse has moved outside the rectangle determined byGetSystemParameters(SM_CXDRAG)andGetSystemParameters(SM_CYDRAG)useSetCaptureto capture the mouse. At this point continue responding toWM_MOUSEMOVEand check forWM_LBUTTONUP. You might want to change the mouse cursor at this point. Also check forWM_CAPTURECHANGED, which means the drag has been aborted. After the drag is complete callReleaseCapture.Edit: Most of this process can be automated with the
DragDetectfunction. Call this function from the WM_LBUTTONDOWN handler.