0
votes

I am creating an application with the win32 api and I have a boolean isLeftClickPressed which is set to true when I receive a WM_LBUTTONDOWN message. when I receive a WM_LBUTTONUP message I set it to false. this works fine, however if I hold down the left mouse button and move my cursor out of the window and release my mouse, it never send a WM_LBUTTONUP message. I am not looking for a way to get around this rather just to find out when my mouse leaves the window and then set isLeftClickPressed to false.

any help would be appreciated.

1
You say you don't want it, but that would be less confusing to the user, and it's easy to do: just call SetCapture on button down and ReleaseCapture on button up, and you will get mouse events even if the cursor leaves the window, until the button is released. - spectras
@spectras you are right, however if I set the capture, and go outside the window my mouse coordinates will go negative. is it possible to only capture mouse clicks? - Jaden
Yes, or you might also simply test if coords are negative and ignore move events in that case. It's totally up too you, I just wanted to mention this so you know it is easy to do. Thus you can pick your solution based on what is the best for your application rather than on which looks easier to implement :) - spectras

1 Answers

2
votes

Call TrackMouseEvent and check for WM_MOUSELEAVE