Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a control receive mouse events after the mouse is dragged beyond its borders?

I'm creating a custom control which recognizes when the mouse is dragging, specifically using messages WM_LBUTTONDOWN, WM_LBUTTONUP, and WM_MOUSEMOVE. When the mouse goes down, I capture the position on the control, and then when the mouse moves, if the left mouse button is down, I do more handling (calculating between starting and ending points).

The problem is, I'm expecting the mouse to go out of the control, and even out of the form, but when the mouse leaves the control, it no longer captures mouse events. Is there a way I can handle specifically the WM_MOUSEMOVE and WM_LBUTTONUP messages without the mouse being over the control?

like image 554
Jerry Dodge Avatar asked Nov 30 '22 04:11

Jerry Dodge


1 Answers

You can use SetCapture/ReleaseCapture Windows API to continue to get mouse events when the cursor moves outside the control.

like image 160
Igor Avatar answered Dec 09 '22 13:12

Igor