Frage

Wie kann man überprüfen, ob die Maus über einen bestimmten HWND ist? Ich habe versucht, die WM_MOUSELEAVE und WM_MOUSEMOVE Nachrichten mit dem Überblick zu behalten, aber wenn Sie die Maus aus dem Button Taste gedrückt und zieht klicken, wird es nicht die WM_MOUSELEAVE erhalten, bis die Maustaste losgelassen wird, was zu spät ist, denn:

Wenn Sie auf eine Schaltfläche klicken, wird die WM_COMMAND-Nachricht nur dann gesendet, wenn:
1. Die Maus wurde ursprünglich über die Taste gedrückt
2. Die Maus ist über die Schaltfläche
3. Die Maus wird über die Taste losgelassen

Ich brauche diese Funktionalität zu replizieren.

War es hilfreich?

Lösung

To duplicate this functionality, just call SetCapture() so that mouse messages are sent to your window even if the mouse leaves it. You can read the current mouse position as it moves and determine if it is still over your window/button (I'm still not 100% sure what you are doing). And, when the mouse button is released, you can call ReleaseCapture() to restore where mouse messages are sent.

EDIT: Oh, and you can use the Windows API function WindowFromPoint() to determine which window the mouse is over.

Andere Tipps

This is built-in to Windows, it is called 'mouse capture', SetCapture(hWnd). It ensures you get mouse messages even though the mouse has moved outside of the window. You call it on the WM_LBUTTONDOWN message notification.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top