Reputation: 849
I am trying to track a moving desktop application window so I can move a corresponding transparent overlay window in parity. Currently, I hook the EVENT_SYSTEM_MOVESIZEEND
event with SetWinEventHook
. Inside my callback, I update the location of my overlay with the new location of the target application window.
This works, but it means that my overlay jumps around after the user lets go of the target window's title bar. I would like my overlay to track the target window as it is moving, not just after it has been moved.
The only way I can think to do this is to also hook the EVENT_SYSTEM_MOVESIZESTART
event. When the START
event fires, spawn a new thread that polls the target windows location and updates my overlay location. Then, when the END
event fires, kill the polling thread.
Is this a reasonable approach, or is there a better way to achieve the functionality I want.
Thanks.
Upvotes: 1
Views: 715
Reputation: 849
As per Hans Passant's suggestion on my question. I was indeed looking to hook EVENT_OBJECT_LOCATIONCHANGE
instead of EVENT_SYSTEM_MOVESIZEEND
. Once I hooked LOCATIONCHANGE
, the tracking worked as expected.
One thing of note, by hooking LOCATIONCHANGE
you will also receive mouse events for the window. You can easily filter the movement of the window by checking the hwnd
of the WinEventProc
callback function.
MSDN:
Handle to the window that generates the event, or NULL if no window is associated with the event. For example, the mouse pointer is not associated with a window.
Upvotes: 2