3

In Delphi 5 this used to work. I have a component that descends from TCustomControl and I implement the cmmouseleave message:

procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;

Now if I am just moving the mouse over the control the message is triggered but if I am moving the mouse while keeping the mouse left button down, the same message is not triggered. AFAIK I have not called the begindrag method and the dragmode is set to manual. Any clue of what could be going on?

4
  • 3
    The mouse is captured when you press the left button. Hence the control will receive mouse move messages (WM_MOUSEMOVE), even if the mouse is outside the control. It will receive mouse leave message when the button is released. I highly doubt this is not the case with D5. Dec 11, 2013 at 17:29
  • thanks yes the mouseleave is triggered only when I release the button, I am not sure but I thought it worked on D5, maybe not. Can I accept this as an answer? Dec 11, 2013 at 17:35
  • You're welcome. I posted the comment as an answer. Dec 11, 2013 at 17:37
  • 2
    CM_MOUSELEAVE was implemented differently in early VCL versions than it is in later versions. The VCL used to manually track the mouse and issue CM_MOUSEENTER and CM_MOUSELEAVE messages when needed. Now it lets the OS track the mouse via TrackMouseEvent() and issues CM_MOUSELEAVE in response to the WM_MOUSELEAVE message. Dec 11, 2013 at 21:27

1 Answer 1

6

The mouse is captured when you press the left button. Hence the control will receive mouse move messages (WM_MOUSEMOVE) even if the mouse is outside the control. It will receive mouse leave message when the button is released. This should also be the case with D5.

You can exclude csCaptureMouse from ControlStyle if you don't want the mouse to be captured in response to a WM_LBUTTONDOWN.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.