1
votes

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.

1
Use EVENT_OBJECT_LOCATIONCHANGE or hide the overlay while it is moving.Hans Passant
@HansPassant Thanks, it seems like this is what I was looking for. I don't know how I missed it, I'll give it a try.forTruce
Another option is to subclass the target window and handle the WM_WINDOWPOSCHANGING message.Remy Lebeau
@RemyLebeau this is not an options since I am tracking another 3rd party application (e.g. Chrome).forTruce

1 Answers

2
votes

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.